-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Grandparent / Parent / Grandchild structure with Adhoc Query
PostPosted: Mon Nov 06, 2006 9:25 am 
Newbie

Joined: Sat Nov 04, 2006 5:14 pm
Posts: 4
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?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.