aspose file tools*
The moose likes Object Relational Mapping and the fly likes Hibernate: session.get() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Hibernate: session.get()" Watch "Hibernate: session.get()" New topic
Author

Hibernate: session.get()

Shaan Shar
Ranch Hand

Joined: Dec 27, 2005
Posts: 1249

Hi Every One,
I have a doubt about session.get() method.we have different overloaded methods with this name.Like..

public Object get(Class clazz,Serializable id)throws HibernateException

and

public Object get(String entityName,Serializable id)throws HibernateException



In the signature of above methods..
1. what is id ? Is it the Primary key in our table?
2. what is entityName in the second method ?

I have a table Event with columns eventId,eventTitle and eventLead.eventId is primary key.
I tried to retrieve data from table depends on eventId value like below..



This works fine for me.

But when i tried to retrieve data depends on eventTitle value like below..




But this time i got an exception like....


Could anyone guide me,how to write code for retrieving all the records related to a particular eventTitle.

Thanks


The Best way to predict your future is to create it - Every great individual common man
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

Yes, the id is only the PK, it cannot be a different field like a String field.

The get method expects the second parameter to be the PK id that uniquely identifies the exact row in the database that the Object will map to.

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Hibernate: session.get()
 
Similar Threads
Id not availble in lazy loaded associate objects
Indexed Collections
elt column hibernate
Composite foreign key causing "object is not an instance of declaring class"?
How to persist objects having circular references using Hibernate