This week's giveaway is in the Programmer Certification (OCPJP) forum.
We're giving away four copies of Java Mock Exams (software) and have David Mayer on-line!
See this thread for details.
Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Hibernate: session.get()

Shaan Shar
Ranch Hand
Posts: 1249
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Mark Spritzler
Posts: 17309
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Happiness is not a goal ... it's a by-product of a life well lived - Eleanor Roosevelt. Tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!