hibernate查询

来源:百度知道 编辑:UC知道 时间:2024/06/25 04:11:30
select name,city from ktv_info where city='592' union all
select name,city from ktv_info where city<>'592'这样的查询语句在hibernate中怎么表示

hql查询
1.
String hql="select name,city from ktv_info where city='592'";
Query query=session.createQuery(hql).unionSet();
2.
String hql="select name,city from ktv_info where city<>'592'";
Query query=session.createQuery(hql).unionSet();

我补充一点楼上兄弟的回答:
如果ktv_info是你的数据库中的表名的话,对映到hibernate中pojo类名肯定不是ktv_info,很可能是KtvInfo,所以在hibernate语句中要使用pojo类名。