Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

CascadeType.ALL is causing Unique key constraint violation exception

 
Ramesh Krishna
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am having trouble while inserting nodes using JPA with the following mapping.

I am using Hibernate JPA 2.0 and the persistance.xml is like the below

<persistence-unit name="ecc" transaction-type="JTA">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>java:comp/env/jdbc/xxxx</jta-data-source>

<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect" />
<property name="hibernate.transaction.manager_lookup_class" value ="org.hibernate.transaction.WebSphereExtendedJTATransactionLookup"/>
<property name="transaction.factory_class" value="org.hibernate.transaction.JTATransactionFactory" />
</properties>

-----------------------
I have Master entity and child entity with oneToMany relation like below.

@OneToMany(mappedBy = "userPreference", fetch=FetchType.EAGER)
@org.hibernate.annotations.CascadeType.ALL

When i process the request then it was trying to do two insert statements(according to hibernate logger statements) for the same and getting exception the unique key violation exception.

Please help me.

Thanks


 
Happiness is not a goal ... it's a by-product of a life well lived - Eleanor Roosevelt. Tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!