-->
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: Simple & quick question!!!
PostPosted: Mon Jul 18, 2005 4:03 pm 
Beginner
Beginner

Joined: Thu Jul 14, 2005 10:11 am
Posts: 32
Hello!!.

I kinda feel stupid for having to ask this... but....

how do i check if there is no other object with the same ID in the db ??. Do i have to query and check if the result is null, or, is there a simpler way ?

Thanks!


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 18, 2005 4:31 pm 
Regular
Regular

Joined: Thu May 26, 2005 2:08 pm
Posts: 99
It would help to know why you want to do this. Are you trying to generate your own ID's for new objects? If so, are you sure that you really want to do this? Hibernate can handle this for you automatically if you want.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 18, 2005 4:53 pm 
Beginner
Beginner

Joined: Thu Jul 14, 2005 10:11 am
Posts: 32
The ID is provided by the user (in this case).

Thanks!


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 18, 2005 4:58 pm 
Senior
Senior

Joined: Sun Jan 04, 2004 2:46 pm
Posts: 147
Just do a

Code:
session.get( MyClass.class, id )


This will return null if there is no row in the db.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 18, 2005 5:27 pm 
Beginner
Beginner

Joined: Thu Jul 14, 2005 10:11 am
Posts: 32
thanks!!!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 19, 2005 3:49 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
"minor" correction. session.get() is not guaranteed to hit the database, e.g. if someone previously have used load() or queried and it has been proxied.

If you want to be sure, do the get() as the very first operation in a session or simply just execute a query to perform a check which will always run against the database.

_________________
Max
Don't forget to rate


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.