-->
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.  [ 5 posts ] 
Author Message
 Post subject: session.load seems to load all ancestors causing deadlocks
PostPosted: Sat Feb 28, 2004 1:26 pm 
Beginner
Beginner

Joined: Tue Nov 18, 2003 12:34 am
Posts: 39
Location: Dallas, Texas, US
Hello,
Recently, I turned on the show_sql and started observing this behavior. I would like to confirm whether this is supposed to happen and curious to know how to optimize it. Currently, I am facing severe deadlock issues.

I need to resolve this ASAP and I greatly appreciate your time and help.

I have typical bidirectional one-to-many with the many-valued end as the inverse end. Let me explain this using a simple example. Entity A has one-to-many with Entity B which then has one-to-many with Entity C. I am doing the following

session.load(Entity C, entity_id)

What I am noticing is that Hibernate is executing the following sql.

select Entity C (expected)
select Entity B (unexpected)
select Entity A (unexpected)
select <other children of Entity A> (highly unexpected)
select <other children of Entity B> (highly unexpected)
....
....

I am curious to know why it is doing a select on the ancestors. Is this is expected? I am asking because I was under the impression that only Entity C would be used and it not happening the way I thought. This is causing DEADLOCK issues to me as it happens to acquire locks on ALL entities preventing legitimate access to the ancestors from the other threads. I would like to add that the database that we use is a single-user database (quadcap.com) that does table-locking instead of row-locking for all queries.

Madhan.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Feb 28, 2004 1:36 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Since you have shown none of the relevant information listed in the huge red message when you post, the answer is a guess at best. Next time read before posting!

Anyway, looks like you have not enabled proxies, so please refer to the Hibernate documentation. Read it from beginning to end.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Feb 28, 2004 2:24 pm 
CGLIB Developer
CGLIB Developer

Joined: Thu Aug 28, 2003 1:44 pm
Posts: 1217
Location: Vilnius, Lithuania
Just execute transactions serialy on singe user database(in synchronized block).


Top
 Profile  
 
 Post subject:
PostPosted: Sat Feb 28, 2004 2:51 pm 
Beginner
Beginner

Joined: Tue Nov 18, 2003 12:34 am
Posts: 39
Location: Dallas, Texas, US
Thanks for your instant response. I apologize. I have included the missing pieces. I am trying to use the proxies in the meantime.

Hibernate version: 2.1.1

<?xml version="1.0"?>

<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

Mapping 1
------------
<hibernate-mapping>
<class
name="DirectorImpl"
table="DIRECTORS"
dynamic-update="true"
dynamic-insert="false"
>

<id
name="id"
column="DIRECTORS_ID"
type="int"
unsaved-value="any"
>
<generator class="assigned">
</generator>
</id>

<many-to-one
name="parent"
class="CEOImpl"
cascade="none"
outer-join="auto"
update="true"
insert="true"
column="CEOS_ID"
not-null="true"
/>

<bag
name="children"
table="MANAGERS"
lazy="false"
inverse="true"
cascade="all"
>
<key
column="DIRECTORS_ID"
/>
<one-to-many
class="ManagerImpl"
/>
</bag>

</class>
</hibernate-mapping>

Mapping 2:
-------------
<?xml version="1.0"?>

<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping>
<class
name="ManagerImpl"
table="MANAGERS"
dynamic-update="true"
dynamic-insert="false"
>

<id
name="id"
column="MANAGERS_ID"
type="int"
unsaved-value="any"
>
<generator class="assigned">
</generator>
</id>

<many-to-one
name="parent"
class="DirectorImpl"
cascade="none"
outer-join="auto"
update="true"
insert="true"
column="DIRECTORS_ID"
not-null="true"
/>

<bag
name="children1"
table="ASSISTANTS"
lazy="false"
inverse="true"
cascade="all"
>

<key
column="MANAGERS_ID"
/>

<one-to-many
class="AssistantImpl"
/>
</bag>

<bag
name="children"
table="EMPLOYEES"
lazy="false"
inverse="true"
cascade="all"
>

<key
column="MANAGERS_ID"
/>

<one-to-many
class="EmployeeImpl"
/>
</bag>

</class>
</hibernate-mapping>

Mapping 3:
------------
<?xml version="1.0"?>

<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping>
<class
name="EmployeeImpl"
table="EMPLOYEES"
dynamic-update="true"
dynamic-insert="false"
>

<id
name="id"
column="EMPLOYEES_ID"
type="int"
unsaved-value="any"
>
<generator class="assigned">
</generator>
</id>

<many-to-one
name="parent"
class="ManagerImpl"
cascade="none"
outer-join="auto"
update="true"
insert="true"
column="MANAGERS_ID"
not-null="true"
/>

<many-to-one
name="parent1"
class="AsistantImpl"
cascade="none"
outer-join="auto"
update="true"
insert="true"
column="ASISTANTS_ID"
not-null="false"
/>

</class>
</hibernate-mapping>

Mapping 4:
-------------
<?xml version="1.0"?>

<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping>
<class
name="AssistantImpl"
table="ASSISTANTS"
dynamic-update="true"
dynamic-insert="false"
>

<id
name="id"
column="ASSISTANTS_ID"
type="int"
unsaved-value="any"
>
<generator class="assigned">
</generator>
</id>

<many-to-one
name="parent"
class="ManagerImpl"
cascade="none"
outer-join="auto"
update="true"
insert="true"
column="MANAGERS_ID"
not-null="true"
/>

<bag
name="children"
table="EMPLOYEES"
lazy="false"
inverse="true"
cascade="all"
>

<key
column="ASSISTANTS_ID"
/>

<one-to-many
class="EmployeeImpl"
/>
</bag>

</class>
</hibernate-mapping>

------------------------------------------------------------------------------
I find it difficult to show the code between openSession() and close() as they are scattered all around. Essentially, what I am doing is instantiating the all the entities involved (and add them to appripriate collections) and then do a store() on the top level entity and commit all the changes. Then, close the session and open a new session and call

session.load(EmployeeImpl.class, new Integer(1005));

-------------------------------------------------------------------------------
This is the partial output on the console:
<EXPECTED> Hibernate: select employeeimp0_.EMPLOYEES_ID as EMPLOYEES1_0_, employeeimp0_.active as active0_, emplo
<UNEXPECTED> Hibernate: select manag0_.MANAGERS_ID as MANAGERS_ID0_, manager0_.DIRECTORS_ID as DIRECTORS_ID0_, c
<UNEXPECTED> Hibernate: select directorimpl0_.DIRECTORS_ID as DIRECTORS_ID0_, directorimpl0_.CEOS_ID as CEO_2_

------------------------------------------------------------------------------
Database: Quadcap 3.2


Top
 Profile  
 
 Post subject:
PostPosted: Sat Feb 28, 2004 3:47 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
If you want lazy loading for a "one side", you need to proxy that class. For an explanation why this is so, please take a look at http://www.hibernate.org/162.html


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