Basic idea is to have Categories within Categories within Categories. Sub Categories can have only one parent Category. A parent Category can have multiple sub categories.
After querying back a category cat (and close the session), The Application needs to know if the category is top level category, where parent is null, the codes is something
if (cat.getParentCat() == null)
{
do something
}
This works fine currently in Hibernate 2.0
However, when I migrate my app to hibernate 3.1.2, it complains the "session has been closed"
My question here is why hibernate need to do the query again? I set the lazy to false.
The mapping is something like:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="au.com.mycpmpany.myproject.entities.Category" table="category">
<id name="id" >
<generator class="native"/>
</id>
<property name="name" type="string"/>
<property name="description" type="string"/>
<many-to-one name="parentCat" class="au.com.mycpmpany.myproject.entities.Category"
column="parentId" lazy="false"/>
</class>
</hibernate-mapping>
|