Hibernate version: 3.1.3
I may have missed it, but I have tried reading through the forum, and I have tried RTFM (I bought the book and read through it multiple times). If I missed my answer somewhere, apologies.
We are migrating a client/server application into a new database. The database structure has a grandparent/parent/grandchild structure. There is one grandparent (master) table, but multiple 'parent' (middle) tables and each 'parent' can have multiple children.
The application will need to persist grandparent/parent or parent/child, but not all three at the same time. Data entry is low-volume, but retrieval is frequent and complex, using an adhoc query generator.
The existing application uses composite natural keys and outer joins on foreign keys to combine output from multiple parent tables with multiple child tables, as well as information from the grandparent.
The grandparent has a 1-column key, which is used as a foreign key by the parent record and combined with a non-unique sequence identifier to uniquely identify the parent. The grandchild takes this a step further and uses a foreign key to the parent key (containing the grandparent key and the parent sequential identifier) plus its own non-unique sequential id to make its own primary key.
The non-unique sequential column on the parent is unique within a given grandparent key value. Ditto for the grandchild to the parent.
Reading throught the book I see that Hibernate doesn't particularly like natural keys. I have no problem changing that, but I need to know the best way to build the relationships between the tables so the adhoc query will retrieve efficiently / quickly. It is not uncommon to join the grandparent, two parents, and one or two grandchild tables. Sometimes it is just grandparent and grandchild. I need to keep the grandparent key information in the parent table and keep both grandparent and parent key info in the grandchild table.
How do I use Hibernate to create a generator ID column as my primary key and still retain the parent and grandparent key information in the lower-level tables?
|