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
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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">

<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" />

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

@OneToMany(mappedBy = "userPreference", fetch=FetchType.EAGER)

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.


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
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!