Hi,
I have two tables
Code:
Parent (PK parentId NOT NULL, FK childId1 NULL, FK childId2 NULL, ...)
Child (PK parentId NOT NULL, PK childId NOT NULL, ...)
The two nullable columns childId1 and childId2 in Parent are foreign keys to Child.childId, and the parent's primary key parentId exists in both tables. I need to map Parent-Child relationships as two one-to-many associations from Parent to Child along the (parentId, childId1) and (parentId, childId2) composite keys. I know how to map a one-to-many when the composite key is the primary key of the Parent or not a primary key of the Parent but this is a hybrid case where the composite key involves both the primary key and an additional column. And as the number of columns in the composite key is different from the number of columns in the Parent's primary key (2 vs. 1) Hibernate rejects this combination. Is this possible to map in Hibernate at all?
For completeness here's how the Java classes look:
Code:
Parent class with fields (parentId : Long, childrenInRole1 : List<Child>, childrenInRole2 : List<Child>, ...)
Child class with fields (childId : Long, parent : Parent, ...)