-->
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: Problem with lazy loading of tree-like structure
PostPosted: Thu Mar 04, 2004 5:20 am 
Newbie

Joined: Thu Mar 04, 2004 5:03 am
Posts: 18
Hi everyone,

Consider the the following (abbreviated) mapping:

Code:
<class name="Location" table="Locations">
<many-to-one
            name="parent"
            class="Location"
            cascade="none"
            outer-join="false"
            update="true"
            insert="true"
            column="parent_id"/>
</class>


The problem that I am encountering is that when I load a node deep in the tree (say a leaf node) hibernate issues enough select stamements to load every node up to the root. For my application this incurs an unacceptable performance hit.

I tried using proxies by adding a
Code:
proxy="Location"
attribute to the class tag. The problem with this that even though it avoid loading the parent location nodes, it doesn't load the actual node itself! So something like (pseudocode):

Code:
session.open();
location = findLocationById(1);
session.close();

.... later ....

Code:
location.getId();


...throws an Exception
Code:
net.sf.hibernate.HibernateException: Could not initialize proxy - the owning Session was closed

because lazily initialized objects cannot be accessed from a session different from the one they were loaded from.

I have also considered using a Set to map the children of each node in hibernate and retrieve the parent with HQL but i am having the same problem of causing exceptions when I access the children from a different session.

I am pretty stuck here and I feel that I have explored all the options provided by the documentation. The advice of someone who has had a similar problem is what I am hoping for.

Thanks in advance,
Giorgos

PS: I am using Hibernate 2.1.2 with MySQL and the Spring Framework


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 04, 2004 5:52 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
You can force initialize the loaded node by using Hibernate.initialize() or by accessing some of its properties.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 04, 2004 10:13 am 
Newbie

Joined: Thu Mar 04, 2004 5:03 am
Posts: 18
Michael,

Thanks for your help.

I would like to ask one more question regarding caching:

What is the effect of using a <cache usage="read-only"> tag for a mutable class? In my mind, and what I would like to achieve, is that when an instance of the specified class is updated it's entry in the cache is simply invalitated. This strategy suits my appliciation as it is mainly read-only (with very few updates).

Thanks again,
Giorgos


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.