-->
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: Whic method to call for where query ?
PostPosted: Wed Dec 21, 2005 12:22 pm 
Beginner
Beginner

Joined: Thu Apr 14, 2005 11:39 am
Posts: 31
I am using Hibernate and Spring. I need to write a query with where cluase.

Ex: select * from Testtable where id=123

Could some tell which method I have to call from this getHibernateTemplate() ?. It should return a list.

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 21, 2005 4:07 pm 
Expert
Expert

Joined: Fri Aug 19, 2005 2:11 pm
Posts: 628
Location: Cincinnati
http://www.springframework.org/docs/api ... tions.html
http://www.springframework.org/docs/api ... essor.html

the HibernateTemplate class uses a SessionFactory just like a normal app would, and there is a getter for that SessionFactory.

_________________
Chris

If you were at work doing this voluntarily, imagine what you'd want to see to answer a question.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 21, 2005 4:10 pm 
Expert
Expert

Joined: Fri Aug 19, 2005 2:11 pm
Posts: 628
Location: Cincinnati
to use direct hql you can just open a new session from the SessionFactory object and use session.createQuery, or one of those custom wrapper methods from the hibernate template will work.

_________________
Chris

If you were at work doing this voluntarily, imagine what you'd want to see to answer a question.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 21, 2005 7:42 pm 
Newbie

Joined: Tue Oct 18, 2005 2:49 pm
Posts: 13
Since you are getting multiple results bacj, I assume id is NOT your primary key.

If you are extending HibernateDaoSupport, you can use this

HibernateTemplate ht = this.getHibernateTemplate();

return ht.findByNamedParam("from TestTable tt where id=:id,
"id", new Long(cityId));


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 21, 2005 7:44 pm 
Newbie

Joined: Tue Oct 18, 2005 2:49 pm
Posts: 13
Since you are getting multiple results back, I assume id is NOT your primary key.

If you are extending HibernateDaoSupport, you can use this

HibernateTemplate ht = this.getHibernateTemplate();
return ht.findByNamedParam("from TestTable tt where id=:id",
"id", new Long(123));

Here TestTable is yr class modeled on the table, and must have a TestTable.hbm.xml hibernate mapping file

-Pratik


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.