-->
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: Urgent!!!! Parent-Child relationship deadlock
PostPosted: Sun Oct 17, 2004 10:31 pm 
Beginner
Beginner

Joined: Sun Jun 20, 2004 11:39 pm
Posts: 24
Hi there,
I am facing deadlock issues when more than 1 thread is trying to do parent.addToChild(child) in a transaction. According to the stacktrace and sql that is shown on the console, i got a "net.sf.hibernate.LazyInitializationException: Failed to lazily initialize a collection" when a parent.addToChild(child) method is called.

which is caused by

Caused by: COM.ibm.db2.jdbc.DB2Exception: [IBM][CLI Driver][DB2/SUN] SQL0911N T
he current transaction has been rolled back because of a deadlock or timeout. R
eason code "2". SQLSTATE=40001

On a successful run of the transaction using only a single thread, i see that there is an sql that retrieves all the children whose parent_id=? which falls in line with the lazyInitializationException above cos it is unable to retrieve the children.

By the way, the parent-child relationship is bidirectional. and inverse="true" is set on the parent side of the r/s

I suspect that because there is more than 1 thread adding children to the same parent and have not commited yet and more than 1 thread is doing a select on retrieving all the children of the same parent, this causes dirty reads.

Is this really the cause of the deadlock? if so how do i set the isolation level of hibernate? Shouldnt this be transparent to us? i mean i am sure that there are applications out there that have threads that add children to the same parent rite? if so have they met with the same problem as me and how did they solve it?

i am using jboss and using hibernate as a mbean service, database is DB2.

Please anyone with any directions pls help!!!!

Best Regards


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 18, 2004 1:41 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
when are you committing?
have you read about giving java code, mapping file, hibernate version...?

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 18, 2004 3:13 am 
Beginner
Beginner

Joined: Sun Jun 20, 2004 11:39 pm
Posts: 24
Hello Anthony,
This is the sequence of events:

Child c = new Child();
c.setProperty().....
c.setProperty().....
c.setProperty().....

Parent p=(Parent)sess.load(Parent.class, new long(1));
c.setParent(p);
p.addToChildren(c);//this is the part that the lazy initialization problem occurs. At any one time , the same parent might be accessed by another thread cos the other thread is creating a new child object and adding it to the same parent.


in the parent mapping file:

<set name="children" inverse="true" cascade="all" lazy="true">
<key column="parent_id"/>
<one-to-many class="Child"/>
</set>



<class name="MainChild" table="MainChild">
<id name="id" type="long" unsaved-value="0">
<generator class="native"/>
</id>

<property name="..." .... />

<many-to-one name="parent" class="Parent" />


<joined-subclass name="Child" table="Child">
<key column="id"/>

<property name="cost" column="cost" not-null="true" type="double"/>
</joined-subclass>

</class>


Hope this is sufficient enuff, if not please let me know

Best Regards


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.