-->
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.  [ 5 posts ] 
Author Message
 Post subject: session.get()
PostPosted: Mon Jun 02, 2008 1:53 pm 
Newbie

Joined: Thu May 01, 2008 4:53 pm
Posts: 11
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..

Code:
int eventId=4;
Event event=(Event)session.get(Event.class,eventId);

This works fine for me.

But when i tried to retrive data depends on eventTitle value like below..
Code:
String eventTitle="Parents meeting";
Event event=(Event)session.get(Event.class,eventTitle);


But this time i got an exception like....
Code:
Exception in thread "main" org.hibernate.TypeMismatchException: Provided id of the wrong type. Expected: class java.lang.Integer, got class java.lang.String
   at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:86)
   at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:878)
   at org.hibernate.impl.SessionImpl.get(SessionImpl.java:815)
   at org.hibernate.impl.SessionImpl.get(SessionImpl.java:808)
   at client.EventManager.retriveEvent(EventManager.java:32)
   at client.TestClient.main(TestClient.java:29)



Please can anybody tell me,how to write code for retrieving all the records related to a particular eventTitle.

Thank q very much.
sirisha.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 03, 2008 1:31 pm 
Newbie

Joined: Thu May 01, 2008 4:53 pm
Posts: 11
Hi Everybody,
Any one please give me suggestions about this..
Thanks,
Siri.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 04, 2008 10:12 am 
Expert
Expert

Joined: Tue May 13, 2008 3:42 pm
Posts: 919
Location: Toronto & Ajax Ontario www.hibernatemadeeasy.com
Yes, it is definitely the entity's primary key that is needed.

Here's a little tutorial on Hibernate's load and get methods that you might really find useful.

http://jpa.ezhibernate.com/Javacode/learn.jsp?tutorial=27hibernateloadvshibernateget

_________________
Cameron McKenzie - Author of "Hibernate Made Easy" and "What is WebSphere?"
http://www.TheBookOnHibernate.com Check out my 'easy to follow' Hibernate & JPA Tutorials


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 04, 2008 10:52 am 
Newbie

Joined: Thu May 01, 2008 4:53 pm
Posts: 11
Thanks Cameron Mckenzie, that tutorial is very helpful.

But i still have one doubt.. How to get a record from a table depends on non primary key.
I posted the situation(getting record depends on non primary key) of my application in my first post.

Can any body please tell me how to solve this problem.I am really stuck with problem.

Any suggestion would be helpful to me..

Thanks,
sirisha.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 04, 2008 11:04 am 
Expert
Expert

Joined: Tue May 13, 2008 3:42 pm
Posts: 919
Location: Toronto & Ajax Ontario www.hibernatemadeeasy.com
When you say non-primary key, do you mean you are searching on a non-unique field? You can always use HQL or a criteria query. More tutorials on these subjects can be found through my signature links.

_________________
Cameron McKenzie - Author of "Hibernate Made Easy" and "What is WebSphere?"
http://www.TheBookOnHibernate.com Check out my 'easy to follow' Hibernate & JPA Tutorials


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.