-->
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.  [ 6 posts ] 
Author Message
 Post subject: session.get() with composite key
PostPosted: Fri Oct 14, 2005 3:14 pm 
Newbie

Joined: Fri Oct 14, 2005 2:35 pm
Posts: 14
I'm trying to do a session.get() on a class with a composite key. How can I do it? Is such a thing possible or do I need to do a session.find() and just get the first result, if there is one?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 14, 2005 3:28 pm 
Expert
Expert

Joined: Mon Jul 04, 2005 5:19 pm
Posts: 720
session.get(Bozo.class, bozoCompId);


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 14, 2005 4:19 pm 
Newbie

Joined: Fri Oct 14, 2005 2:35 pm
Posts: 14
Ok, but how do I construct the composite id bozoCompId?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 14, 2005 4:24 pm 
Expert
Expert

Joined: Fri Aug 19, 2005 2:11 pm
Posts: 628
Location: Cincinnati
if you are using hbm2java the following will generate your PK class
Code:
...
<composite-id name="comp_id" class="package.ClassPK">
<meta attribute="generated-class" inherit="false">packageClassPK</meta>
...


if not using hbm2java, handwrite it. hibernate will know how to handle a PK object

_________________
Chris

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


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 14, 2005 4:24 pm 
Expert
Expert

Joined: Mon Jul 04, 2005 5:19 pm
Posts: 720
BozoCompId bozoCompId = new bozoCompId();
bozoCompId.setOne(1);
bozoCompId.setTwo(2);


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 14, 2005 6:50 pm 
Newbie

Joined: Fri Oct 14, 2005 2:35 pm
Posts: 14
Ah ok. Up until now I didn't have an actual class that represented the composite id. I didn't know you needed one since it doesn't seem to be in the docs. Thanks kochcp.


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