-->
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.  [ 3 posts ] 
Author Message
 Post subject: One-to-Many & Many-to-One relations with composite ids
PostPosted: Tue Sep 12, 2006 10:51 am 
Newbie

Joined: Tue Sep 12, 2006 10:18 am
Posts: 4
Location: Porto / Portugal
Hibernate 3.1 and Hibernate Annotations 3.2.0.CR1

My problem is that i can't annotate correctly the relations between my identities that have composite Ids.
In my cenario i have a entity A that can have more than one entities B, wich herself can have more than one entities C. So one entity A has many Bs, and one entity B as manys entities C. The big thing here is that A has a composite id that is part of the composite id of B , wich B's id is part of the composite id of C.
My code is:

Code:


@Embeddable
public class A_Pk implements Serializable{

   private Integer number;
   private String type;

   ... getters and setters
}

@Entity
@Table(name="A")
public class A {

   private A_Pk a_Pk;
   private String description;
   
   private List b;

@EmbeddedId
   @AttributeOverrides({
     @AttributeOverride(name="number”, column=@Column(name="number")),
     @AttributeOverride(name="type", column=@Column(name="type"))
   })
   public geta_Pk() {
  ...

  @OneToMany( mappedBy = "b_Pk", cascade = { CascadeType.PERSIST, CascadeType.REMOVE })
  public List<B> getb() {

   ... getters and setters
}


@Embeddable
public class B_Pk implements Serializable{

   private A_Pk a_Pk;
   private String type;

   ... getters and setters
}

@Entity
@Table(name="B")
public class B {

   private B_Pk b_Pk;
   private String description;
   
  private A a;
   private List c;

@EmbeddedId
   @AttributeOverrides({
     @AttributeOverride(name="type", column=@Column(name="btype"))
   })
   public getb_Pk() {
  ...

  @ManyToOne
   @JoinColumns({
     @JoinColumn(name = "number", referencedColumnName="number"),
     @JoinColumn(name = "type", referencedColumnName="type")
   })
  public geta() {
  ...
  @OneToMany( mappedBy = "c_Pk", cascade = { CascadeType.PERSIST, CascadeType.REMOVE })
  public List<C> getc() {

   ... getters and setters
}
   


@Embeddable
public class C_Pk implements Serializable{

   private B_Pk b_Pk;
   private String type;

   ... getters and setters
}

@Entity
@Table(name="C")
public class C {

   private C_Pk c_Pk;
   private String description;
   
  private B b;

@EmbeddedId
   @AttributeOverrides({
     @AttributeOverride(name="type", column=@Column(name="ctype"))
   })
   public getc_Pk() {
  ...

  @ManyToOne
   @JoinColumns({
     @JoinColumn(name = "number", referencedColumnName="number"),
     @JoinColumn(name = "type", referencedColumnName="type")
     @JoinColumn(name = "btype", referencedColumnName="btype")
   })
  public getb() {
  ...
   ... getters and setters
}



I would like an ideia of how to annotate this correctly... i'm not sure of this definition of class B and C...
Many thanks!


Last edited by ht on Tue Sep 12, 2006 11:36 am, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 12, 2006 11:34 am 
Newbie

Joined: Wed Sep 06, 2006 10:06 am
Posts: 11
Location: Lisbon, Portugal
I'm quite a newbie in here but i believe that this :

Code:
@Embeddable
public class C_Pk implements Serializable{

   private C_Pk c_Pk;
   private String type;

   ... getters and setters
}


should be :

Code:
@Embeddable
public class C_Pk implements Serializable{

   private B_Pk b_Pk;
   private String type;

   ... getters and setters
}
[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 12, 2006 11:48 am 
Newbie

Joined: Tue Sep 12, 2006 10:18 am
Posts: 4
Location: Porto / Portugal
Thanks... typing error...

Where from the same country, want to exchange some info by email ?
here is mine ;)
hilariot
@
gmail

Abraço


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