-->
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.  [ 3 posts ] 
Author Message
 Post subject: Cascade All persisting leads to StackOverflowError
PostPosted: Tue Nov 02, 2010 11:10 am 
Newbie

Joined: Fri Dec 05, 2008 11:31 am
Posts: 6
We are using Hibernate 3.2.6. We have a tree of elements that link to each other in a form like this:

Tree.hbm.exml
<many-to-one name="root" column="elementId" cascade="all"/> <!-- points to a first Element -->
<set name="allElements" inverse="true" cascade="all-delete-orphan"><key column="ownerTreeId"/><one-to-many class="..."/></set> <!-- Contains all Element objects that belong to this tree -->
...

Element.hbm.xml:
<many-to-one name="left" column="elementId" cascade="all"/> <!-- points back to another Element -->
<many-to-one name="right" column="elementId" cascade="all"/><!-- points back to another Element -->
<many-to-one name="ownerTree" column="ownerTreeId"/> <!-- points back to Root
...

Everything works fine to the point when the tree contains about 300 elements. When the Tree contains more than 300 elements and we attempt to save it, the process fails with a StackOverflowError coming from Hibernate. The stack trace circles around 10 different methods over and over:

at org.hibernate.engine.CascadingAction$6.cascade(CascadingAction.java:245)
at org.hibernate.engine.Cascade.cascadeToOne(Cascade.java:268)
at org.hibernate.engine.Cascade.cascadeAssociation(Cascade.java:216)
at org.hibernate.engine.Cascade.cascadeProperty(Cascade.java:169)
at org.hibernate.engine.Cascade.cascade(Cascade.java:130)
at org.hibernate.event.def.AbstractSaveEventListener.cascadeBeforeSave(AbstractSaveEventListener.java:431)
at org.hibernate.event.def.DefaultMergeEventListener.entityIsTransient(DefaultMergeEventListener.java:178)
at org.hibernate.event.def.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:123)
at org.hibernate.impl.SessionImpl.fireMerge(SessionImpl.java:687)
at org.hibernate.impl.SessionImpl.merge(SessionImpl.java:669)
at org.hibernate.engine.CascadingAction$6.cascade(CascadingAction.java:245)
at org.hibernate.engine.Cascade.cascadeToOne(Cascade.java:268)
at org.hibernate.engine.Cascade.cascadeAssociation(Cascade.java:216)
at org.hibernate.engine.Cascade.cascadeProperty(Cascade.java:169)
at org.hibernate.engine.Cascade.cascade(Cascade.java:130)
at org.hibernate.event.def.AbstractSaveEventListener.cascadeBeforeSave(AbstractSaveEventListener.java:431)
at org.hibernate.event.def.DefaultMergeEventListener.entityIsTransient(DefaultMergeEventListener.java:178)
at org.hibernate.event.def.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:123)
at org.hibernate.impl.SessionImpl.fireMerge(SessionImpl.java:687)
at org.hibernate.impl.SessionImpl.merge(SessionImpl.java:669)
...

but the top of the stack shows this:
at org.hibernate.event.AbstractEvent.<init>(AbstractEvent.java:21)
at org.hibernate.event.MergeEvent.<init>(MergeEvent.java:35)
at org.hibernate.event.MergeEvent.<init>(MergeEvent.java:20)
at org.hibernate.impl.SessionImpl.merge(SessionImpl.java:669)


We find it a little odd that only 300 elements in the tree are causing stack overflow. Is there a different way of solving this problem than assigning cascade="all" in the hbm.xml files? Is saving each element of the tree manually and removing cascade="all" from all the hbm.xml files a better solution?

The "allElements" set stores the references to all Element objects that belong to the tree. Is it possible that having multiple references to the same element could be causing the StackOverflowError? Is a set up like this problematic/would you say that we should never have objects with multiple references to the same element?

If an implementation like this is ok and the StackOverflowError is a result of a bug, has such a bug been logged already and possibly addressed in a more recent release of Hibernate?


Top
 Profile  
 
 Post subject: Re: Cascade All persisting leads to StackOverflowError
PostPosted: Mon Jul 30, 2012 2:53 pm 
Newbie

Joined: Fri Dec 05, 2008 11:31 am
Posts: 6
Quite a long time has passed and we are still struggling with this. In short, what is the best practice in storing a linked list using Hibernate? Or maybe is it better to change the structure and make it something else than a linked list?


Top
 Profile  
 
 Post subject: Re: Cascade All persisting leads to StackOverflowError
PostPosted: Tue Jul 31, 2012 6:40 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
There was a bug in Hibernate 3.6 in which in some exceptional mappings the Cascade resolution would get stuck in a circular dependency. The cascading logic was redesigned in Hibernate 4 to avoid this.

So you either upgrade to Hibernate 4 or have to avoid this by change your mapping; disabling cascade or slightly changing the relations should do the trick.

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.