Dear all,
I wanna create a many to many self join, from table User.
Each user (might) have multiple parent-users (superiors)
Each user (might) have multiple child-users (subordinate)
Hibernate version = 2.1.2
Database = SQL Server 2000
User.java :
import java.util.*;
public class User
{
private String id;
private String userName;
private Set child;
private Set parent;
public String getId()
{
return id;
}
public Set setId(String theId)
{
id = theId;
}
public String getParent()
{
return parent;
}
public void setParent(Set theParent)
{
parent = theParent;
}
public String getChild()
{
return child;
}
public void setChild(String theChild)
{
child = theChild;
}
}
User.hbm.xml :
<hibernate-mapping>
<!-- id auto generation -->
<class name="com.andrewtani.User" table="USERS">
<id name="id" column="ID">
<generator class="uuid.string" />
</id>
<bag name="parent" table="Parent_Child" lazy="true">
<key column="Parent_ID"/>
<many-to-many class="User" column="Child_ID"/>
</bag>
<bag name="child" table="Parent_Child" inverse="true" lazy="true">
<key column="Child_ID"/>
<many-to-many class="eg.Node" column="Parent_ID"/>
</bag>
</class>
</hibernate-mapping>
My question is : Will this code work?
If I wanna create, do I have to create parent and child in ONE SESSION ? or could I do that in several session? would that violate any constraints??
Thanks all
|