-->
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.  [ 5 posts ] 
Author Message
 Post subject: many to many association without PK
PostPosted: Sat Sep 26, 2009 7:28 am 
Newbie

Joined: Sat Sep 26, 2009 5:18 am
Posts: 3
Hi

I have a object Node with :
class Node {
private int id // PK
private int objId
..... other properties
}

and object Element with:

class Element {
private int id // PK
private int nodeObjId
........ other properties
}

and i try to create many-to-many relation between them by objId and nodeObjId.

Do you have any idea ?


Top
 Profile  
 
 Post subject: Re: many to many association without PK
PostPosted: Tue Sep 29, 2009 5:53 am 
Beginner
Beginner

Joined: Wed Nov 19, 2008 6:39 am
Posts: 44
Location: Mumbai, India
Create reference(foreign key) in both classes and try.

_________________
Thx,
Murugesan.
Web: http://www.murugesanpitchandi.com


Top
 Profile  
 
 Post subject: Re: many to many association without PK
PostPosted: Tue Sep 29, 2009 5:54 am 
Beginner
Beginner

Joined: Wed Nov 19, 2008 6:39 am
Posts: 44
Location: Mumbai, India
refer this...


Code:
<!-- bi-directional many-to-many association to Department -->
<set name="departments" table="employees_departments" inverse="true" cascade="all">
   <key column="employee_id"/>
   <many-to-many column="department_id" class="com.warfrog.hibernatetutorial2.hibernate.Department"/>
</set>


Now open Department and repeat the procedure pasting this code instead:


Code:
<!-- bi-directional many-to-many association to Employee -->
<set name="employees" table="employees_departments" cascade="all">
   <key column="department_id"/>
   <many-to-many column="employee_id" class="com.warfrog.hibernatetutorial2.hibernate.Employee"/>
</set>

_________________
Thx,
Murugesan.
Web: http://www.murugesanpitchandi.com


Top
 Profile  
 
 Post subject: Re: many to many association without PK
PostPosted: Tue Sep 29, 2009 6:13 am 
Beginner
Beginner

Joined: Sat Aug 01, 2009 5:28 am
Posts: 42
use join table,

http://docs.jboss.org/hibernate/core/3. ... ional-join

this link may help you

_________________
Warm Regards,
Tarun Walia


Top
 Profile  
 
 Post subject: Re: many to many association without PK
PostPosted: Sun Oct 04, 2009 4:37 am 
Newbie

Joined: Sat Sep 26, 2009 5:18 am
Posts: 3
thank you for your answers, but i found a solution.

The idea to create many-to-many association between these objects was wrong.

in class Node :

Code:
<set name="elements" table="elements" cascade="all">
   <key column="node_obj_id" property-ref="objId" />
   <one-to-many class="com.Element"/>
</set>


and the solution is to use column and property-ref in the same time


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.