-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Cascade delete problem in Parent-child pointing same table
PostPosted: Mon Dec 10, 2007 1:35 pm 
Newbie

Joined: Mon Dec 10, 2007 1:04 pm
Posts: 1
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:


Top
 Profile  
 
 Post subject: Re: Cascade delete problem in Parent-child pointing same tab
PostPosted: Tue Dec 11, 2007 7:16 pm 
Expert
Expert

Joined: Wed Apr 11, 2007 11:39 am
Posts: 735
Location: Montreal, QC
ravin wrote:
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?



As a workaround I removed the not null constrain on parent field and everything else looked fine for me but I still need to find out why this is confusing hibernate. I did a test and you can not actually save items either.


Farzad-


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.