-->
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: Loading an Object
PostPosted: Fri Aug 06, 2004 11:48 am 
Beginner
Beginner

Joined: Fri Jan 16, 2004 4:58 pm
Posts: 37
I am trying to load an Object where I know the ID. The documentation and the Hibernate In Action book both give similar examples:

Code:
Employee emp = (Employee)session.get(Employee.class, empId);


Where empId is the known identifier. Problem is, the 2.1.4 API doesn't allow this particular get method. It wants (Class, Serializable) or (Class, Serializable, LockMode).

So what is the correct way to retrieve a simple object when the identifier is known? And why does the documentation say that something will work that doesn't?

Thanks.

_________________
Gregg Bolinger
Javaranch Sheriff
Weblog


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 06, 2004 11:51 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Whats wrong with Serializable?

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 06, 2004 11:53 am 
Beginner
Beginner

Joined: Fri Jan 16, 2004 4:58 pm
Posts: 37
I change my empId to a String and placed it in the get method which works. Still wondering why the docs are a bit vague on that fact though.

_________________
Gregg Bolinger
Javaranch Sheriff
Weblog


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 06, 2004 12:01 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
I don't understand your problem. I don't even know what "empId" is, because you didn't tell me.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 06, 2004 12:10 pm 
Beginner
Beginner

Joined: Fri Jan 16, 2004 4:58 pm
Posts: 37
Ok, I have a form that asks for an Employee ID number so that I can lookup that employee. The empId is the value I get from the form and it is the ID column in the employee_table.

I understand now that I can just pass my empId as a String to the get() method.

_________________
Gregg Bolinger
Javaranch Sheriff
Weblog


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 06, 2004 12:13 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
No, you should use the appropriate wrapper type to wrap any primitive value to it's Serializable counterpart, not just use String whenever you think it might work. That's basic Java. You won't have to do this anymore in JDK 1.5.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 06, 2004 1:20 pm 
Beginner
Beginner

Joined: Fri Jan 16, 2004 4:58 pm
Posts: 37
Doh! Thaks Christian. I got it now. The help is always appreciated.

_________________
Gregg Bolinger
Javaranch Sheriff
Weblog


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.