Gethibernatetemplate.find has multiple parameters to use

Source: Internet
Author: User

by sequential placeholders. To populate the parameters:

1) Hibernate 2 is populated with the Session.find method

Session.find ("From TUser user where user.name=?", "Erica", hibernate.string);

Multiple parameter conditions:

object[] args = new object[] {"Erica", New Integer (20)};
type[] types = new type{hibernate.string, Hibernate.integer};
Session.find ("From TUser user where user.name=?") And user.age=? ", args, types);

2) parameter padding via the query interface:

Query query = Session.createquery ("From TUser user where user.name=?") and User.age>? ");
Query.setstring (0, "Erica");
Query.setinteger (1, 20);

To populate parameters by referencing placeholders:

String hql = "from TUser where Name=:name";
Query query = session.createquery (HQL);
Query.setparameter ("name", "Erica");

How to pass a parameter of two time types to the second parameter of find

Public List findAll (date begin, date end) throws Exception {
String hql= "from Salebill where Saledate bewteen? and? ";
Object[] Value={begin,end};
List List = This.gethibernatetemplate (). Find (hql, value);
return list;

List morecats = This.gethibernatetemplate (). Find (
"From Cat as Cat where" + "Cat.name = ' Fritz ' or cat.id =?" or cat.id =? ",
New object[] {id1, id2},
New type[] {hibernate.long, hibernate.long}
);

Public Auctionuser Finduserbyitemandprice (Integer itemId, Double Price)
{
object[] args = {itemId, price};
List L = gethibernatetemplate (). Find ("from bid as bid where bid.bidItem.id =? and Bid.bidprice =? ", args);
if (L.size () >= 1)
{
Bid B = (BID) l.get (0);
return B.getbiduser ();
}
Else
{
return null;
}

}

Above Source: http://hi.baidu.com/solidbullet/blog/item/1e1027462ada912f8794731e.html (solidbullet space)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.