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,orphanRemov al=true)
@Cascade(value={org.hibernate.annotations.CascadeT ype.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.AbstractFlushingEventListe ner performExecutions Could not synchronize database state with session
org.hibernate.exception.ConstraintViolationExcepti on: Could not execute JDBC batch update
at org.hibernate.exception.SQLStateConverter.convert( SQLStateConverter.java:96)
at org.hibernate.exception.JDBCExceptionHelper.conver t(JDBCExceptionHelper.java:66)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(Ab stractBatcher.java:275)
at org.hibernate.engine.ActionQueue.executeActions(Ac tionQueue.java:262)
at org.hibernate.engine.ActionQueue.executeActions(Ac tionQueue.java:178)
at org.hibernate.event.def.AbstractFlushingEventListe ner.performExecutions(AbstractFlushingEventListene r.java:321)
at org.hibernate.event.def.DefaultFlushEventListener. onFlush(DefaultFlushEventListener.java:51)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.j ava:1206)
at org.hibernate.impl.SessionImpl.managedFlush(Sessio nImpl.java:375)
at org.hibernate.ejb.AbstractEntityManagerImpl$1.befo reCompletion(AbstractEntityManagerImpl.java:1057)
at org.hibernate.transaction.WebSphereExtendedJTATran sactionLookup$TransactionManagerAdapter$Transactio nAdapter$1.invoke(WebSphereExtendedJTATransactionL ookup.java:209)
at $Proxy215.beforeCompletion(Unknown Source)
at com.ibm.ws.jtaextensions.SynchronizationCallbackWr apper.beforeCompletion(SynchronizationCallbackWrap per.java:65)
at com.ibm.ws.Transaction.JTA.RegisteredSyncs.distrib uteBefore(RegisteredSyncs.java:242)
at com.ibm.ws.Transaction.JTA.TransactionImpl.prePrep are(TransactionImpl.java:2408)
at com.ibm.ws.Transaction.JTA.TransactionImpl.stage1C ommitProcessing(TransactionImpl.java:1641)
at com.ibm.ws.Transaction.JTA.TransactionImpl.process Commit(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(T ranManagerSet.java:167)
at com.ibm.ws.Transaction.JTA.UserTransactionImpl.com mit(UserTransactionImpl.java:293)
at com.swissre.ecc.web.ECCTransFilter.doFilter(ECCTra nsFilter.java:68)
at com.ibm.ws.webcontainer.filter.FilterInstanceWrapp er.doFilter(FilterInstanceWrapper.java:190)
at com.ibm.ws.webcontainer.filter.WebAppFilterChain.d oFilter(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.han dleRequest(ServletWrapper.java:588)
at com.ibm.ws.wswebcontainer.servlet.ServletWrapper.h andleRequest(ServletWrapper.java:524)
at com.ibm.ws.webcontainer.servlet.CacheServletWrappe r.handleRequest(CacheServletWrapper.java:90)
at com.ibm.ws.webcontainer.WebContainer.handleRequest (WebContainer.java:751)
at com.ibm.ws.wswebcontainer.WebContainer.handleReque st(WebContainer.java:1478)
at com.ibm.ws.webcontainer.channel.WCChannelLink.read y(WCChannelLink.java:125)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLi nk.handleDiscrimination(HttpInboundLink.java:458)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLi nk.handleNewInformation(HttpInboundLink.java:387)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLi nk.ready(HttpInboundLink.java:267)
at com.ibm.ws.tcp.channel.impl.NewConnectionInitialRe adCallback.sendToDiscriminators(NewConnectionIniti alReadCallback.java:214)
at com.ibm.ws.tcp.channel.impl.NewConnectionInitialRe adCallback.complete(NewConnectionInitialReadCallba ck.java:113)
at com.ibm.ws.tcp.channel.impl.AioReadCompletionListe ner.futureCompleted(AioReadCompletionListener.java :165)
at com.ibm.io.async.AbstractAsyncFuture.invokeCallbac k(AbstractAsyncFuture.java:217)
at com.ibm.io.async.AsyncChannelFuture.fireCompletion Actions(AsyncChannelFuture.java:161)
at com.ibm.io.async.AsyncFuture.completed(AsyncFuture .java:136)
at com.ibm.io.async.ResultHandler.complete(ResultHand ler.java:196)
at com.ibm.io.async.ResultHandler.runEventProcessingL oop(ResultHandler.java:751)
at com.ibm.io.async.ResultHandler$2.run(ResultHandler .java:881)
at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.j ava:1497)
Caused by: java.sql.BatchUpdateException: ORA-00001: unique constraint (ECAB2.UNIQUE_USER_HEADER) violated

at oracle.jdbc.driver.DatabaseError.throwBatchUpdateE xception(DatabaseError.java:343)
at oracle.jdbc.driver.OraclePreparedStatement.execute Batch(OraclePreparedStatement.java:10768)
at com.ibm.ws.rsadapter.jdbc.WSJdbcStatement.executeB atch(WSJdbcStatement.java:705)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch( BatchingBatcher.java:70)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(Ab stractBatcher.java:268)
... 43 more

thank you
Ram