I'm attempting to create a one-to-many collection that is joined on an arbitrary column of the parent table rather than on the primary key. That is, I want the following tables:
Parent
Code:
Parent
------
uniqueId (PK)
otherId
.....
Child
-----
uniqueId (PK)
parentOtherId
.......
Where rather than parentOtherId being a foreign key to uniqueId of the Parent table, it's a foreign key to the otherId column of Parent. That is, when loading the children of parent the SQL executed is something along the lines of
Code:
SELECT * FROM Child where parentOtherId = ?
I've been unable to find a way of mapping this relationship so that hibernate will load the collection appropriately. Rather than load
The reason I want this odd mapping is I wish to maintain a version history of all changes to the mapped objects. Unfortunately the history table solution suggested in a number of forum posts won't work as I need to be able to load previous versions of the entire object graph as efficiently as the current version. So I want all versions including the current in a single table with the associations based off a separate key from the database primary key. Then I can use filters to restrict the loaded objects for a given session to the current version or the version as of some date.
Thanks in advance.