File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Hibernate: session.get()" Watch "Hibernate: session.get()" New topic

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


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.


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

Joined: Feb 05, 2001
Posts: 17276

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.


Perfect World Programming, LLC - iOS Apps
How to Ask Questions the Smart Way FAQ
I agree. Here's the link:
subject: Hibernate: session.get()
jQuery in Action, 3rd edition