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