-->
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.  [ 7 posts ] 
Author Message
 Post subject: lookup "composite key" objects on the session
PostPosted: Tue Mar 16, 2004 9:31 am 
Newbie

Joined: Thu Aug 28, 2003 7:14 am
Posts: 18
I am using Hibernate 2.1,
how can I find out if there is an instance of some persistent object associated with the session? The class has COMPOSITE KEY.
thanks,
MIchael


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 16, 2004 9:46 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
session.load(class, serializable) look at javadoc
for composite id, a best practice is to have a class reprenting the composite id. This class must implements serializable so you can also use it for session.load


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 16, 2004 10:01 am 
Expert
Expert

Joined: Fri Feb 06, 2004 7:49 am
Posts: 255
Location: Moscow, Russia
delpouve wrote:
session.load(class, serializable) look at javadoc
for composite id, a best practice is to have a class reprenting the composite id. This class must implements serializable so you can also use it for session.load

from the javadoc
You should not use this method to determine if an instance exists (use find() instead). Use this only to retrieve an instance that you assume exists, where non-existence would be an actual error.
use the following approach:
Code:
Integer count =
    (Integer)session.find("count(obj) from YourClass obj where obj.id.key1=val1 AND obj.id.ke2=val2").iterate().next();


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 16, 2004 10:14 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
shl is right,
i misunderstood the initial question, i thought you wanted to retrieve and object from the session ( that is to say, you know the object is in the session...)


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 16, 2004 10:17 am 
Newbie

Joined: Thu Aug 28, 2003 7:14 am
Posts: 18
no delpouve, actually you are right since that was exactly my question.
thanks ALL


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 16, 2004 10:25 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
everybody is right , that's cool :)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 17, 2004 10:36 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Eheh! After Xtrem Programming, now Xtrem Supporting :)

_________________
Emmanuel


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