-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 
Author Message
 Post subject: Insert record issue
PostPosted: Fri May 07, 2010 4:20 am 
Newbie

Joined: Fri May 07, 2010 4:13 am
Posts: 4
Hi

I am trying to insert record in the parent-child table(one-to-many) mapping... I am getting the following error when inserting record in the child table.

org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:69)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:202)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:230)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:140)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:296)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1007)
at com.ava.audit.hibernate.AuditLogListener.onPostInsert(AuditLogListener.java:184)
at org.hibernate.action.EntityInsertAction.postInsert(EntityInsertAction.java:115)
at org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:100)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:243)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:227)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:140)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:296)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1007)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:354)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
at audittest.EventTest.main(EventTest.java:52)
Caused by: java.sql.BatchUpdateException: ORA-01400: cannot insert NULL into ("EBAMDEV"."AUDIT_ENTITY_PROPERTY_DTL"."ENTITY_PROPERTY")

at oracle.jdbc.driver.DatabaseError.throwBatchUpdateException(DatabaseError.java:674)
at oracle.jdbc.driver.OraclePreparedStatement.executeBatch(OraclePreparedStatement.java:9394)
at oracle.jdbc.driver.OracleStatementWrapper.executeBatch(OracleStatementWrapper.java:211)
at org.apache.commons.dbcp.DelegatingStatement.executeBatch(DelegatingStatement.java:294)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:58)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:195)
... 17 more

plz Help me in resolving this issue...
thanks in advance,
ambika.


Top
 Profile  
 
 Post subject: Re: Insert record issue
PostPosted: Fri May 07, 2010 4:47 am 
Expert
Expert

Joined: Tue Jun 16, 2009 3:36 am
Posts: 990
field "EBAMDEV"."AUDIT_ENTITY_PROPERTY_DTL"."ENTITY_PROPERTY" is declared in you schema as not nullable,
so it not allowed to insert records into table "EBAMDEV"."AUDIT_ENTITY_PROPERTY_DTL" with having the column
ENTITY_PROPERTY value not specified (= null).

Solutions:
Either declare the field ENTITY_PROPERTY nullable (and apply the schema change on the database)
or guarantee that ENTITY_PROPERTY value is always initialized in the moment where you persist a new AUDIT_ENTITY_PROPERTY_DTL.


Top
 Profile  
 
 Post subject: Re: Insert record issue
PostPosted: Fri May 07, 2010 4:57 am 
Newbie

Joined: Fri May 07, 2010 4:13 am
Posts: 4
Thanks for the reply.

Yes the field is not nullable (It should be). I am passing the correct value (not null..i checked) for the field "EBAMDEV"."AUDIT_ENTITY_PROPERTY_DTL"."ENTITY_PROPERTY". Still i am getting this error.

This is my code.
Transaction saveAuditTx = session.beginTransaction();
//Parent entity object
AuditMst audit_mst = new AuditMst();
audit_mst.setEntityPkID(event.getId().toString());
audit_mst.setActorID(actorId.toString());
audit_mst.setActionTime(new Timestamp((transTime).getTime()));
audit_mst.setEntityID(5);
audit_mst.setEventID(OPERATION_TYPE_INSERT);
audit_mst.setMaker(actorId);
audit_mst.setMakerDate(new Timestamp((transTime).getTime()));
session.save(audit_mst);
Set<AuditEntityPropertyDtl> audProperties = new HashSet<AuditEntityPropertyDtl>();
for (String propertyName : event.getPersister().getPropertyNames()) {
System.out.println("property name " + audit_mst.getAuditID());
newPropValue = event.getPersister().getPropertyValue(
event.getEntity(), propertyName, entityMode);

// Child entity objects
AuditEntityPropertyDtl audit_prop_dtl = new AuditEntityPropertyDtl();
if (newPropValue != null) {
if (!(newPropValue instanceof Collection)) {
audit_prop_dtl.setAuditID(audit_mst.getAuditID());
audit_prop_dtl.setEntityProperty(propertyName);
audit_prop_dtl.setEntityPropertyOldValue("");
audit_prop_dtl.setEntityPropertyNewValue(newPropValue
.toString());
audit_prop_dtl.setMaker(actorId);
audit_prop_dtl.setMakerDate(new Timestamp(new Date()
.getTime()));
audit_prop_dtl.setChecker(actorId);
audit_prop_dtl.setCheckerDate(new Timestamp(new Date()
.getTime()));
}
}
audProperties.add(audit_prop_dtl);
session.save(audit_prop_dtl);
System.out.println("entity id " + audit_prop_dtl.getAuditPropertyID());
}
session.save(audit_mst);
session.flush();
audit_mst.setAuditProperties(audProperties);
session.save(audit_mst);
session.flush();
saveAuditTx.commit();
session.close();


Top
 Profile  
 
 Post subject: Re: Insert record issue
PostPosted: Fri May 07, 2010 5:41 am 
Expert
Expert

Joined: Tue Jun 16, 2009 3:36 am
Posts: 990
Are you sure that line

Code:
audit_prop_dtl.setEntityProperty(propertyName);


is effectively called ? (both if-condtions must be true in order that this block is executed)

And are you sure that propertyName contains a value that is different than null ?

N.B.: There's an AuditLogListener involved !! (see stacktrace AuditLogListener.java:184)
What is AuditLogListener actually doing? Maybe it does further inserts or modifications which
lead to the exception?


Top
 Profile  
 
 Post subject: Re: Insert record issue
PostPosted: Fri May 07, 2010 6:10 am 
Newbie

Joined: Fri May 07, 2010 4:13 am
Posts: 4
Yes.. Its sure its reaching that line and the value sent to it is not null...

Then Inside AuditLogListener class i have this code to insert the record.
The error line,
at com.ava.audit.core.AuditLogListener.onPostInsert(AuditLogListener.java:191).
This line is the 7th line of my code(from down) which is session.flush();

Thanks,
Ambika.


Top
 Profile  
 
 Post subject: Re: Insert record issue
PostPosted: Fri May 07, 2010 6:43 am 
Newbie

Joined: Fri May 07, 2010 4:13 am
Posts: 4
Issue solved. Thanks a lot for the replies. One value was null. That was the problem.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.