-->
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.  [ 2 posts ] 
Author Message
 Post subject: Help on design decision Composite keys
PostPosted: Tue Aug 22, 2006 9:38 am 
Newbie

Joined: Thu Nov 04, 2004 3:08 am
Posts: 5
Location: United Kingdom
Hi,

We are using hibernate during the design of our project.

As the current database model stands, it appears that if natural keys are used as primary keys it would make querying easier.In addition we plan to denormalise some data as we wish to avoid complex joins and reduce time execution of the query.

The problem is we need to make a decision on usage of composite keys in a table, as due to the use of natural keys , most tables will need to have a composite key.

We need to know in hibernate what are the pros and mostly cons of using composite keys.

There are 2 approaches in our mind.

1. Use the hibernate composite keys as recommended, ie.

<composite-key>
<key-many-to-one id=address class=address lazy=true>
<composite-key>

Here we wish to avoid a join on address table.how do we achieve this, as we understand lazy will not query address table howver if we call getkey it will then load the address table along with other keys which form part of the composite key.
We want to avoid this, can we avoid it, as we always need to call getkey

2. Use hibernate composite keys in a workaround manner.

In order to ensure that hibernate does not fire a join, define composite keys as
<composite-key>
<key-many-to-one id=address column=address>
<composite-key>

i.e use as a regular key without mapping to parent table to avoid the join.

Could you please tell me the best approach from design point of view and problems with hibernate composite keys.

THIS IS URGENT , PLEASE HELP


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 22, 2006 10:43 am 
Expert
Expert

Joined: Fri Aug 19, 2005 2:11 pm
Posts: 628
Location: Cincinnati
You could just map the composite key without it pointing to the parent.

i.e.
Code:
<composite-key>
   <key-property>
...
</composite-key>

in a very sql-maps kinda way. eliminating the benefits of hibernate.

but if you ever wish to traverse the relationship in an object oriented manner, or ever want hibernate to run this join, you won't be able to

_________________
Chris

If you were at work doing this voluntarily, imagine what you'd want to see to answer a question.


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

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.