I have one Catalog class which has the following mapping file.
For example, the catalog table has such record:
id | name | iconurl | pid
1 AAA NULL NULL
2 BBB NULL 1
3 CCC NULL 2
I want to get certain catalog's path up to top most parent with the following code piece:
while (true) {
parentCatalog = catalog.getCatalog();
if (parentCatalog == null) {
break;
}
System.err.println("@ converted path is "+ convertedPath);
convertedPath = parentCatalog.getName() + convertedPath;
};
But the loop never exits. It seems catalog.getCatalog() always returns the valid top most catalog object (id = 1) along the path even when its pid is NULL.
What's wrong here ?
Any help is appreciated !
Code:
<?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="hibernate.Catalog"
table="catalog"
proxy="hibernate.Catalog"
dynamic-update="false"
dynamic-insert="false"
mutable="true"
>
<id
name="id"
column="id"
type="long"
unsaved-value="null"
>
<generator class="native">
</generator>
</id>
<property
name="name"
type="java.lang.String"
update="true"
insert="true"
column="name"
not-null="false"
unique="false"
/>
<property
name="iconUrl"
type="java.lang.String"
update="true"
insert="true"
column="iconurl"
not-null="false"
unique="false"
/>
<many-to-one
name="catalog"
class="hibernate.Catalog"
cascade="none"
outer-join="false"
update="true"
insert="true"
column="pid"
unique="false"
/>
<set
name="subCatalogs"
table="Catalog"
lazy="true"
inverse="false"
cascade="delete"
sort="unsorted"
>
<key
column="pid"
/>
<one-to-many
class="hibernate.Catalog"
/>
</set>
<set
name="objectiveQuestions"
table="objectiveQuestion"
lazy="true"
inverse="false"
cascade="delete"
sort="unsorted"
>
<key
column="cid"
/>
<one-to-many
class="hibernate.QuestionObjective"
/>
</set>
<set
name="subjectiveQuestions"
table="subjectiveQuestion"
lazy="true"
inverse="true"
cascade="delete"
sort="unsorted"
>
<key
column="cid"
/>
<one-to-many
class="hibernate.QuestionSubjective"
/>
</set>
<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-Catalog.xml
containing the additional properties and place it in your merge dir.
-->
</class>
</hibernate-mapping>