With lazy loading you should not have to worry about any of infinite loop(though, i think you loop/tree would still be finite with lazy loading off)
This works for me. You can see by the example.
Code:
public void testAdminer() throws Exception {
AdminDAO ad = new AdminDAO();
Iterator itr = ad.findAll().iterator();
while (itr.hasNext()) {
Admin a = (Admin) itr.next();
if (a.getUpdatedBy() == null) {
System.out.println("I am admin " + a.getFirstname() +
" I was updated by nobody");
} else {
System.out.println("I am admin " + a.getFirstname() +
" I was updated by " + a.getUpdatedBy().getFirstname());
}
}
}
data
Quote:
'id','loginid','firstname','PASSWORD','ADMINTYPE','updatedBy'
'1','login1','god','pass','1','[NULL]'
'2','login2','child1','pass','1','1'
'3','login3','child2','pass','1','1'
'0','login4','childof2','pas','3','3'
output
Quote:
I am admin god I was updated by nobody
I am admin child1 I was updated by god
I am admin child2 I was updated by god
I am admin childof2 I was updated by child2
mapping
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="com.diamondip.netcontrol.model.Admin"
table="adminer"
>
<id
name="id"
type="int"
column="ID"
>
<generator class="native" />
</id>
<property
name="loginid"
type="java.lang.String"
column="LOGINID"
length="32"
/>
<property
name="password"
type="java.lang.String"
column="PASSWORD"
length="255"
/>
<property
name="firstname"
type="java.lang.String"
column="FIRSTNAME"
length="50"
/>
<many-to-one name="updatedBy" column="updatedBy" class="com.diamondip.netcontrol.model.Admin"/>
<property
name="adminType"
type="java.lang.String"
column="ADMINTYPE"
length="32"
update="false"
/>
<!-- associations -->
</class>
</hibernate-mapping>