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!