Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
I am having scenario where my parent child relation points to the same table, with cascade enabled my inserts/ updates works as expected but when i try to perform a delete operation I get a "not-null property references a null or transient value" exception.
for a scenario of one record (here, the same record become parent & child), In my debugging I found that hibernate deletes the records cascade collections first (delete the entity in childern first) and then tries to delete the entity itself (not there as this has been delete in cascade collection) and thus getting the exception.
any thoughts how could i get this running?
Hibernate version:
3.2.5 with Jboss seam 2.0GA
Mapping documents:
Code:
@Entity
@Table(name = "INV_item")
public class Item {
....
@ManyToOne(cascade=CascadeType.ALL,fetch = FetchType.LAZY)
@JoinColumn(name = "parent_id", nullable = false)
@NotNull
public Item getParent() {
return parent;
}
@OneToMany(cascade=CascadeType.ALL,fetch = FetchType.LAZY, mappedBy = "parent")
@NotFound(action=NotFoundAction.IGNORE)
@org.hibernate.annotations.Cascade({org.hibernate.annotations.CascadeType.ALL, org.hibernate.annotations.CascadeType.DELETE_ORPHAN } )
public Set<Item> getChildren() {
return this.children;
}
...
}
Code between sessionFactory.openSession() and session.close():Full stack trace of any exception that occurs:Code:
Caused by: javax.persistence.PersistenceException: org.hibernate.PropertyValueException: not-null property references a null or transient value: com.ilipse.pse.catalog.Item.parent
at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:630)
at org.hibernate.ejb.AbstractEntityManagerImpl.remove(AbstractEntityManagerImpl.java:252)
at org.hibernate.search.jpa.impl.FullTextEntityManagerImpl.remove(FullTextEntityManagerImpl.java:90)
at org.jboss.seam.persistence.EntityManagerProxy.remove(EntityManagerProxy.java:145)
at org.jboss.seam.framework.EntityHome.remove(EntityHome.java:61)
at com.ilipse.pse.crm.ItemHome.remove(ItemHome.java:148)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.jboss.seam.util.Reflections.invoke(Reflections.java:21)
at org.jboss.seam.intercept.RootInvocationContext.proceed(RootInvocationContext.java:31)
at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:56)
at org.jboss.seam.core.BijectionInterceptor.aroundInvoke(BijectionInterceptor.java:46)
at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
at org.jboss.seam.persistence.ManagedEntityIdentityInterceptor.aroundInvoke(ManagedEntityIdentityInterceptor.java:48)
at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
at org.jboss.seam.transaction.RollbackInterceptor.aroundInvoke(RollbackInterceptor.java:31)
at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
at org.jboss.seam.transaction.TransactionInterceptor$1.work(TransactionInterceptor.java:38)
at org.jboss.seam.util.Work.workInTransaction(Work.java:40)
at org.jboss.seam.transaction.TransactionInterceptor.aroundInvoke(TransactionInterceptor.java:32)
at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
at org.jboss.seam.core.MethodContextInterceptor.aroundInvoke(MethodContextInterceptor.java:42)
at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:106)
at org.jboss.seam.intercept.JavaBeanInterceptor.interceptInvocation(JavaBeanInterceptor.java:155)
at org.jboss.seam.intercept.JavaBeanInterceptor.invoke(JavaBeanInterceptor.java:91)
at com.ilipse.pse.crm.ItemHome_$$_javassist_7.remove(ItemHome_$$_javassist_7.java)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.jboss.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:328)
... 50 more
Caused by: org.hibernate.PropertyValueException: not-null property references a null or transient value: com.ilipse.pse.catalog.Item.parent
at org.hibernate.engine.Nullability.checkNullability(Nullability.java:72)
at org.hibernate.event.def.DefaultDeleteEventListener.deleteEntity(DefaultDeleteEventListener.java:250)
at org.hibernate.event.def.DefaultDeleteEventListener.onDelete(DefaultDeleteEventListener.java:141)
at org.hibernate.event.def.DefaultDeleteEventListener.onDelete(DefaultDeleteEventListener.java:52)
at org.hibernate.impl.SessionImpl.fireDelete(SessionImpl.java:766)
at org.hibernate.impl.SessionImpl.delete(SessionImpl.java:744)
at org.hibernate.ejb.AbstractEntityManagerImpl.remove(AbstractEntityManagerImpl.java:246)
... 82 more
Name and version of the database you are using:
mysql 5.0
The generated SQL (show_sql=true):
Debug level Hibernate log excerpt: