I have a table A, B and AB. A and B each have primary keys. AB has a composite key of foreign keys to A and B. How do I model this in hibernate? So far, I've created four classes:
Code:
public class A
{
private String aId;
public String getAId()
public void setAId(String);
}
public class B
{
private String bId;
public String getBId()
public void setBId(String);
}
public class AB
{
private ABKey id;
public void setId(ABKey);
public ABKey getId();
}
public class ABKey
{
private A aId;
private B bId;
public void setA(A);
public A getA();
public void setB(B);
public B getB();
}
So to model the parent-child relationship, I assume I would add a Set of type AB to A and B, i.e.:
Code:
public class A
{
// ... see above
private Set ab; // a Set of ABs
public void setAb(Set);
public Set getAb();
}
// class B would get the same
Now, do I add a property of type A and type B to AB? i.e.
Code:
public class AB
{
// ... see above
private A a;
private B b;
// get and set methods omitted
}
Or is that already handled because of the ABKey composite-id?? Can I model AB as a one-to-many or do I have to use a composite-element because it has a composite key??
RMC