1.
public
void testHQLselect2(){
String hql = "from User where firstname=?";
Query query = session.createQuery(hql);
query.setString(0, "xxx");
query.list();
}
String hql = "from User where firstname=?";
Query query = session.createQuery(hql);
query.setString(0, "xxx");
query.list();
}
生成的sql:
select user0_.firstname as firstname0_,
user0_.lastname as lastname0_,
user0_.age as age0_,
user0_.address as address0_,
user0_.tel as tel0_,
user0_.zipcode as zipcode0_,
user0_.email as email0_
from t_user user0_
where firstname = ?
user0_.lastname as lastname0_,
user0_.age as age0_,
user0_.address as address0_,
user0_.tel as tel0_,
user0_.zipcode as zipcode0_,
user0_.email as email0_
from t_user user0_
where firstname = ?
2.
public
void testHQLselect(){
String hql = "from User where firstname=:firstname";
Query query = session.createQuery(hql);
query.setParameter( "firstname", "xxxx");
query.list();
}
String hql = "from User where firstname=:firstname";
Query query = session.createQuery(hql);
query.setParameter( "firstname", "xxxx");
query.list();
}
生成的SQL:
同上
本文转自 randy_shandong 51CTO博客,原文链接:http://blog.51cto.com/dba10g/246707,如需转载请自行联系原作者