-->
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: why seperate composite class
PostPosted: Sun Oct 22, 2006 4:47 pm 
Newbie

Joined: Thu Apr 27, 2006 12:21 am
Posts: 4
I read some thing about how to mapping a composite key in the hibernate (against legacy db). It is recommended to seperate a composite key columns to a sperate class. Could you please provide what are advantages or disadvantages with this approach? -- or it is only way?

Thanks!
Ben



Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:

Mapping documents:

Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:

Name and version of the database you are using:

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:


Problems with Session and transaction handling?

Read this: http://hibernate.org/42.html


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 27, 2006 10:01 am 
Newbie

Joined: Mon Nov 14, 2005 1:19 pm
Posts: 3
What I've found when mapping composite keys to a separate class, is that it's much easier to load the class. I'm using Spring, so with the primary key of any hibernate mapping, I can just pass it off to the fetchById() method, and it will return the object I want.


However, it makes querying with the criteria api a bit trickier. If I recall correctly (and please let me know if I'm wrong) you have to create a criteria on the main class and then create a subcriteria on the composite key class to add your restrictions.


Anymore, I do more querying than fetching by id, so I don't abstract the composite key elements into a seperate class. That's my preference.

Hope this helps.


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.