-->
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: Loading an Object without an Id
PostPosted: Tue Jul 10, 2007 3:16 pm 
Newbie

Joined: Thu May 31, 2007 7:24 pm
Posts: 4
Let us say that I have a database that contains personell information. The table consists of the following columns:

A number that uniquely identifies the employee
A string containing their first name, not necessarily unique
A string containing their last name, not necessarily unique
Other miscellaneous information

Let us further say that I know for a fact that nobody in the company has the exact same name, nor will they. Is it possible to load an object from this table while only giving Hibernate the first and last name? Or do I have to do a SQL call to explicitly discover the id number, then load the object using that?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 10, 2007 4:13 pm 
Expert
Expert

Joined: Thu Jul 05, 2007 9:38 am
Posts: 287
you can load the objects by lastname/firstname without a problem.

You have three options:
- write a sql statement
- use HQL (looks like SQL but actually isn't)
- Construct the query using Java Objects (this has a fancy name too, but I don't know it)

I can't give you an example, but maybe this section (14.9) from the docu helps:
http://www.hibernate.org/hib_docs/refer ... ryhql.html

And at the end of 1.2.6 you can see how to use HQL to get a list of objects
http://www.hibernate.org/hib_docs/refer ... ersistence

I personally love the java way to construct the query.

You can get an idea of it here:
http://www.hibernate.org/hib_docs/refer ... teria.html

regards
Jens


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 10, 2007 4:41 pm 
Newbie

Joined: Thu May 31, 2007 7:24 pm
Posts: 4
Excellent! I was trying like mad to avoid having to put in explicit queries since I'm trying to keep things as general as possible, and the Java Objects method is exactly the kind of thing I was looking for. Thanks.


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.