This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Object Relational Mapping and the fly likes JPA 2.0 CascadeType.ALL is inserting two rows for each call Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "JPA 2.0 CascadeType.ALL is inserting two rows for each call" Watch "JPA 2.0 CascadeType.ALL is inserting two rows for each call" New topic
Author

JPA 2.0 CascadeType.ALL is inserting two rows for each call

Ramesh Krishna
Greenhorn

Joined: May 17, 2004
Posts: 25
I am using JPA 2.0 and Hibernate JTA transactions. I am having a problem when trying to insert row on a one to many relationship:

my parent Class: public class UserPreference implements Serializable


@OneToMany(mappedBy = "userPreference",fetch=FetchType.EAGER,orphanRemoval=true)
@Cascade(value={org.hibernate.annotations.CascadeType.ALL})
private Set<UserHeader> userHeaders; // child class reference

Child Class:

public class UserHeader implements Serializable

@ManyToOne
@JoinColumn(name="user_sr_id")
private UserPreference userPreference; (Master reference)


When I try to insert a child entity (userHeaders) then it is inserting two rows and the same leading to Unique Key Constraints exception

5/2/11 19:44:24:085 IST] 00000021 SystemOut O Hibernate: select header_.header_uid, header_.attribute_name as attribute2_4_, header_.header_type as header3_4_, header_.mandatory_ind as mandatory4_4_, header_.header_name as header5_4_, header_.header_order_nbr as header6_4_ from ECAB2.header header_ where header_.header_uid=?
[5/2/11 19:44:24:272 IST] 00000021 SystemOut O Hibernate: insert into ECAB2.user_header (creation_date, header_uid, modify_date, header_order_nbr, user_sr_id, user_header_uid) values (?, ?, ?, ?, ?, ?)
[5/2/11 19:44:24:491 IST] 00000021 SystemOut O Hibernate: insert into ECAB2.user_header (creation_date, header_uid, modify_date, header_order_nbr, user_sr_id, user_header_uid) values (?, ?, ?, ?, ?, ?)
[5/2/11 19:44:24:632 IST] 00000022 SystemOut O Hibernate: select docbase0_.docbase_uid as docbase1_2_, docbase0_.docbase_name as docbase2_2_ from ECAB2.docbase docbase0_
[5/2/11 19:44:24:882 IST] 00000022 SystemOut O Hibernate: select objecttype0_.docbase_uid as docbase4_2_1_, objecttype0_.object_type_uid as object1_1_, objecttype0_.object_type_uid as object1_5_0_, objecttype0_.docbase_uid as docbase4_5_0_, objecttype0_.object_type_name as object2_5_0_, objecttype0_.object_desc as object3_5_0_ from ECAB2.object_type objecttype0_ where objecttype0_.docbase_uid=?
[5/2/11 19:44:24:897 IST] 00000021 JDBCException W org.hibernate.util.JDBCExceptionReporter logExceptions SQL Error: 1, SQLState: 23000
[5/2/11 19:44:24:897 IST] 00000021 JDBCException E org.hibernate.util.JDBCExceptionReporter logExceptions ORA-00001: unique constraint (ECAB2.UNIQUE_USER_HEADER) violated

[5/2/11 19:44:24:897 IST] 00000021 JDBCException W org.hibernate.util.JDBCExceptionReporter logExceptions SQL Error: 1, SQLState: 23000
[5/2/11 19:44:24:897 IST] 00000021 JDBCException E org.hibernate.util.JDBCExceptionReporter logExceptions ORA-00001: unique constraint (ECAB2.UNIQUE_USER_HEADER) violated

[5/2/11 19:44:24:897 IST] 00000021 AbstractFlush E org.hibernate.event.def.AbstractFlushingEventListener performExecutions Could not synchronize database state with session
org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:96)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:275)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:262)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:178)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:51)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1206)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:375)
at org.hibernate.ejb.AbstractEntityManagerImpl$1.beforeCompletion(AbstractEntityManagerImpl.java:1057)
at org.hibernate.transaction.WebSphereExtendedJTATransactionLookup$TransactionManagerAdapter$TransactionAdapter$1.invoke(WebSphereExtendedJTATransactionLookup.java:209)
at $Proxy215.beforeCompletion(Unknown Source)
at com.ibm.ws.jtaextensions.SynchronizationCallbackWrapper.beforeCompletion(SynchronizationCallbackWrapper.java:65)
at com.ibm.ws.Transaction.JTA.RegisteredSyncs.distributeBefore(RegisteredSyncs.java:242)
at com.ibm.ws.Transaction.JTA.TransactionImpl.prePrepare(TransactionImpl.java:2408)
at com.ibm.ws.Transaction.JTA.TransactionImpl.stage1CommitProcessing(TransactionImpl.java:1641)
at com.ibm.ws.Transaction.JTA.TransactionImpl.processCommit(TransactionImpl.java:1612)
at com.ibm.ws.Transaction.JTA.TransactionImpl.commit(TransactionImpl.java:1547)
at com.ibm.ws.Transaction.JTA.TranManagerImpl.commit(TranManagerImpl.java:247)
at com.ibm.ws.Transaction.JTA.TranManagerSet.commit(TranManagerSet.java:167)
at com.ibm.ws.Transaction.JTA.UserTransactionImpl.commit(UserTransactionImpl.java:293)
at com.swissre.ecc.web.ECCTransFilter.doFilter(ECCTransFilter.java:68)
at com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:190)
at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:130)
at com.ibm.ws.webcontainer.filter.WebAppFilterChain._doFilter(WebAppFilterChain.java:87)
at com.ibm.ws.webcontainer.filter.WebAppFilterManager.doFilter(WebAppFilterManager.java:837)
at com.ibm.ws.webcontainer.filter.WebAppFilterManager.doFilter(WebAppFilterManager.java:680)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:588)
at com.ibm.ws.wswebcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:524)
at com.ibm.ws.webcontainer.servlet.CacheServletWrapper.handleRequest(CacheServletWrapper.java:90)
at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:751)
at com.ibm.ws.wswebcontainer.WebContainer.handleRequest(WebContainer.java:1478)
at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:125)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:458)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewInformation(HttpInboundLink.java:387)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.ready(HttpInboundLink.java:267)
at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.sendToDiscriminators(NewConnectionInitialReadCallback.java:214)
at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.complete(NewConnectionInitialReadCallback.java:113)
at com.ibm.ws.tcp.channel.impl.AioReadCompletionListener.futureCompleted(AioReadCompletionListener.java:165)
at com.ibm.io.async.AbstractAsyncFuture.invokeCallback(AbstractAsyncFuture.java:217)
at com.ibm.io.async.AsyncChannelFuture.fireCompletionActions(AsyncChannelFuture.java:161)
at com.ibm.io.async.AsyncFuture.completed(AsyncFuture.java:136)
at com.ibm.io.async.ResultHandler.complete(ResultHandler.java:196)
at com.ibm.io.async.ResultHandler.runEventProcessingLoop(ResultHandler.java:751)
at com.ibm.io.async.ResultHandler$2.run(ResultHandler.java:881)
at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1497)
Caused by: java.sql.BatchUpdateException: ORA-00001: unique constraint (ECAB2.UNIQUE_USER_HEADER) violated

at oracle.jdbc.driver.DatabaseError.throwBatchUpdateException(DatabaseError.java:343)
at oracle.jdbc.driver.OraclePreparedStatement.executeBatch(OraclePreparedStatement.java:10768)
at com.ibm.ws.rsadapter.jdbc.WSJdbcStatement.executeBatch(WSJdbcStatement.java:705)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:70)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:268)
... 43 more

thank you
Ramesh
 
 
subject: JPA 2.0 CascadeType.ALL is inserting two rows for each call