sql - Cannot insert NULL values into database -


we use jpa load/persist our entities in prostges database. in 1 case must persist entity native query. heres code:

string sql = "insert recording (id,creationdate,duration,endtime,filemaninfocomplete,lastupdated,packagesdeletetime,rcinfocomplete,"                 + "rcrecordingkept,recordstate,recordingtype,starttime,tenantid,recordingnode_id,transcription_id) "                 + "values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"; query query = getentitymanager().createnativequery(sql); query.setparameter(1, recording.getid()); query.setparameter(2, new date(), temporaltype.timestamp); query.setparameter(3, recording.getduration()); query.setparameter(4, recording.getendtime(), temporaltype.timestamp); query.setparameter(5, recording.isfilemaninfocomplete()); query.setparameter(6, new date(), temporaltype.timestamp); query.setparameter(7, recording.getpackagesdeletetime(), temporaltype.timestamp); query.setparameter(8, recording.isrcinfocomplete()); query.setparameter(9, recording.isrcrecordingkept()); query.setparameter(10,recording.getrecordstate() != null ? recording.getrecordstate().tostring() : recordstate.default); query.setparameter(11,recording.getrecordingtype()!= null ? recording.getrecordingtype().tostring() : null); query.setparameter(12,recording.getstarttime(), temporaltype.timestamp);         query.setparameter(13,recording.gettenantid());         query.setparameter(14,recording.getrecordingnode() != null ? recording.getrecordingnode().getid() : null);         query.setparameter(15, recording.gettranscription() != null ? recording.gettranscription().getid() : null);         query.executeupdate(); 

the insert works finde unless "getpackagesdeletetime" returns null. in case following message ist shown:

caused by: org.postgresql.util.psqlexception: fehler: spalte »packagesdeletetime« hat typ timestamp without time zone, aber der ausdruck hat typ character varying   hinweis: sie müssen den ausdruck umschreiben oder eine typumwandlung vornehmen.   position: 252 

(ie:

error: column "packagesdeletetime" has type timestamp without time zone, expression of type character varying hint: must rewrite expression or typecast. 

)

generated statement looks like:

insert recording(id,creationdate,duration,endtime,filemaninfocomplete,lastupdated,packagesdeletetime,rcinfocomplete,rcrecordingkept,recordstate,recordingtype,starttime,tenantid,recordingnode_id,transcription_id) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) bind => [0c850391-cae9-4ac2-9381-b252167fa239, 2013-04-18 08:38:00.704, 20240, 2013-04-18 08:37:24.131, false, 2013-04-18 08:38:00.704, null, false, true, default, voice, 2013-04-18 08:37:03.891, f56251a7-44df-4151-aa0d-7c3fc538f621, null, null] 

some tips how solve problem?

the corresponding field in entity has annotated with:

@column(nullable=true)

also check corresponding column in table allows null (has no not null constraint). if doesn't please post code of entity.


Comments

Popular posts from this blog

node.js - Bad Request - node js ajax post -

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -