-->
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: Question about associatoin class mapping!
PostPosted: Fri May 05, 2006 4:04 am 
Newbie

Joined: Sat Nov 05, 2005 8:59 pm
Posts: 16
Hello,
Suppose there is an many to many association between Class A and Class B.
Class A_B is their association class. Now i have following code with mapping annotation:

Class A
Code:
@Entity(access=AccessType.FIELD)
public class A implements Serializable {
   
   @OneToMany( mappedBy="role_a")
   private List<A_B> a_B = new ArrayList( );
   
   @Id(generate=GeneratorType.IDENTITY)
   public long id;
        .....


Class B
Code:
@Entity(access=AccessType.FIELD)
public class B implements Serializable {
   
       @OneToMany(mappedBy="role_b")
   private A_B a_B = null;
   
   @Id(generate=GeneratorType.IDENTITY)
   public long id;
   
        .....


Class A_B
Code:
@Entity(access=AccessType.FIELD)
public class A_B implements Serializable {
   
   @ManyToOne(cascade=CascadeType.All)
   private A role_a = new AA();
   
   @ManyToOne(cascade=CascadeType.All)
   private B role_b = new B();
        .......


How can i make the fields "role_b" and "role_a" in Class A_B to be composite primary key????


any help would be appreciated


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 25, 2006 3:02 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
use a composite key mapping the ids and define a @ManyToOne on the same underlying columns beiing insert=false, update=false

_________________
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.