Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

CascadeType.ALL is causing Unique key constraint violation exception  RSS feed

 
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


 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!