For the record, this wasn't my idea. Any the DA's experience and comprehension is so far ahead of mine it is inconceivable I question their design or patterns.
I have three tables:
Customer, Client, Group
Customer has an integer key:cust_id
Client has a composite index of [FK to Customer, Integer key:client_id]
Group has a composite index of [FK to Customer, FK to Client, Integer Key:group_id]
Just trying to figure out the correct way to map this. Technically, the composite id for Group contains the composite index for client. Agh!
Here is what I have so far:
Customer
Code:
public class Customer implements java.io.Serializable {
private Integer custId;
....
Map
Code:
<hibernate-mapping>
<class name="hibernate.generated.Customer" table="CUST">
<id name="custId" type="int">
<column name="CUST_ID" />
<generator class="assigned" />
</id>
....
ClientId
Code:
public class ClientId implements java.io.Serializable {
private Customer custId;
private int clntId;
...
Map
Code:
<hibernate-mapping>
<class name="Client" table="CLIENT" >
<composite-id name="id" class="hibernate.generated.ClientId">
<key-many-to-one class="Customer" name="custId">
<column name="CUST_ID" />
</key-many-to-one>
<key-property name="clntId" type="int">
<column name="CLNT_ID" />
</key-property>
</composite-id>
....
Group
Code:
public class GroupId implements java.io.Serializable {
private Client clntId;
private Integer grpId;
...
Map
Code:
<hibernate-mapping>
<class name="hibernate.generated.Group" table="GRP" >
<composite-id name="id" class="hibernate.generated.GroupId">
<key-many-to-one name="clntId" class="hibernate.generated.Client">
<column name="CLNT_ID" />
<column name="CUST_ID" />
</key-many-to-one>
<key-property name="grpId" type="int">
<column name="GRP_ID" />
</key-property>
</composite-id>
....
Of course, as is, finding groups by the ID listed above doesn't work.
Any help, ideas, or a better way of doing things (besides redesigning the schema, which is out of my control and is impossible. Trust me) is appreciated.
Disclaimers: I own the beginning hibernate book. It has a three sentence section on composite ids. Don't bother asking why the DA's love composite indexes. I don't know. I also read the manual on composite id's. I also have searched the forums and google extensively. I know i'm probably not the only person that has had this problem. I apologize if this is a stupid question, just answer it or tell me where to look for the answer. I am capable of reading and comprehending. I apologize if you read this and it makes you angry. I apologize if you read this and you feel I wasted part of your life.
Thank you