Hibernate Exception When Deleting OneToMany EJB3 Entity
michael.litherland Jun 27, 2006 10:10 AMHi,
I've created a OneToMany bidirectional relationship between two tables. The problem I'm having is a Hibernate exception when I go to delete the child object. According to the EJB3 book recently published by O'reilly it says to ensure the operation is performed from the ManyToOne side or the database operations won't happen. It's when I do this that I get the exception (optional = false on the ManyToOne so I have to use the EM and just do a remove).
parent.getKids().remove(kid); em.remove(kid); // Throws exception
throws
Caused by: javax.persistence.PersistenceException: org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session: [com.ati.raa.entities.TdmUserMapping#4 52] at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.jav a:567) at org.hibernate.ejb.AbstractEntityManagerImpl.remove(AbstractEntityManagerImpl.java:225) at org.jboss.ejb3.entity.TransactionScopedEntityManager.remove(TransactionScopedEntityManager.java:187 ) at com.ati.raa.bl.UserLogicBean.removeUserMapping(UserLogicBean.java:98) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:585) at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:112) at org.jboss.ejb3.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:166) at org.jboss.ejb3.interceptor.EJB3InterceptorsInterceptor.invoke(EJB3InterceptorsInterceptor.java:63) at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101) at org.jboss.ejb3.entity.TransactionScopedEntityManagerInterceptor.invoke(TransactionScopedEntityManag erInterceptor.java:54) at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101) at org.jboss.ejb3.AllowedOperationsInterceptor.invoke(AllowedOperationsInterceptor.java:47) at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101) at org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:79) ... 49 more
If it's relevant I'm using JBoss 4.0.4.GA on Java 1.5.0_06 (OS X) talking to PostgreSQL 8.1, and of course the EJB3 deployment profile for JBoss.
I'm sure this is something I'm not sure about with the session, but I've been really beating myself up over this for about a week now and I need to resolve the issue. Any help would be much appreciated.
Thanks,
Mike