File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hibernate: session.get()

 
Shaan Shar
Ranch Hand
Posts: 1249
Java Spring Ubuntu
  • 0
  • 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

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
 
Mark Spritzler
ranger
Sheriff
Posts: 17276
6
IntelliJ IDE Mac Spring
  • 0
  • 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.

Mark
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic