I have a category. A category can have other children category, and a parent category.
This is the mapping file:
<?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="model.Category" table="category">
<id name="id" column="category_id" type="long" unsaved-value="null">
<generator class="native"/>
</id>
<property name="name" type="string"/>
<property name="description" type="string"/>
<set name="children" lazy="true" cascade="save-update" inverse="true">
<key column="category_id"/>
<one-to-many class="model.Category"/>
</set>
<many-to-one name="parent" column="parent_id" class="model.Category" cascade="none"/>
</hibernate-mapping>
Now in the source code i retireve a category with
Category cat = session.get(id);
then i close the session and i try to retry the parent, and the parent of the parent.
I expected to obtain an error, instead hibernate seems to have loaded the whole tree from the current category to the root (but not the children due to the lazy attribute setted to true in the children set).
I am a begginer so i would like to ask you if there is the possibility to lazy initialize also the many-to-one association.
|