-->
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.  [ 3 posts ] 
Author Message
 Post subject: How to query using EntityManager.find() if PK got 2 fields?
PostPosted: Fri May 02, 2008 3:07 am 
Regular
Regular

Joined: Wed Apr 12, 2006 12:49 am
Posts: 105
Location: Malaysia
Hi,

How to query using EntityManager.find() if my entity class primary key is made of 2 fields?

Please advise.

Regards,
Jap.

_________________
Thank you.

Regards,
Jap.


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 02, 2008 5:12 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Hi,

In case of composite keys one has to work with an embedded class as the primary key representation. An instance of this primary key class can then be passed to find(). See http://www.hibernate.org/hib_docs/annotations/reference/en/html_single/#d0e1662.

If you want to keep the two fields which make up your primary key separated in your entity have a look at @IdClass.

--Hardy


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 02, 2008 6:17 am 
Regular
Regular

Joined: Wed Apr 12, 2006 12:49 am
Posts: 105
Location: Malaysia
Yes, thanks.
I tried, it works.

_________________
Thank you.

Regards,
Jap.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.