-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: creating many to many self-join association.. how to??
PostPosted: Mon Mar 08, 2004 3:41 am 
Beginner
Beginner

Joined: Wed Feb 25, 2004 5:54 am
Posts: 30
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


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 08, 2004 8:50 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Yes.
No if parent and child are created, associated them won't violate any contraints

_________________
Emmanuel


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.