1.hql更新
String hql = "update PhUser set realName=?";
int row=this.getSession().createQuery(hql).setString(0, "小李想").executeUpdate();
PhUser 类名
2.hql删除
String hql = "delete PhUser a where a.userId=2";
int row=this.getSession().createQuery(hql).executeUpdate();
还有个这种的格式:
final String hql = "delete PhRoleFunction as a where a.roleId = "
+ roleId;
this.getHibernateTemplate().execute(new HibernateCallback() {
public Object doInHibernate(Session session)
throws HibernateException, SQLException {
return session.createQuery(hql).executeUpdate();
}
});更新也可以写成这样的格式
3.hql单表查询
String hql = "from PhUser a where a.userId=" + userId;
List list = this.getHibernateTemplate().find(hql);
4.hql多表查询
(1)String hql = "select new map(a.CUId as CUId,a.unitName as unitName,b.CUFId as CUFId,b.UFName as UFName) from PhCorrelativeUnit a,PhCorrelativeUnitFunction b where a.CUId=b.CUId";
List list = this.getHibernateTemplate().find(hql);
多个表的字段放到map中,map的键值就是as后面的别名,如果没有as就是字段名
(2) String hql = "select new com.phantom.appeal.action.bean.DealPaper(a.id as id,a.billId as billId,a.state as state,a.creator as creator,a.createtime as createtime ,b.eventContent as eventContent ,c.realName as realName,b.billCode as billCode,b.citName as citName ) from PhDealBill a,PhAcceptBill b,PhUser c where a.departmentId="+ billid+ " and a.state=0 and a.billId=b.billId and a.creator =c.userId order by a.billId";
return this.getHibernateTemplate().find(hql);
另外就是写一个类,对应你要查询的字段,这里的类名是new com.phantom.appeal.action.bean.DealPaper,里面对应查询的字段名
5.得到记录数
String hql = "select count(*) from PhUser";
List list = this.getHibernateTemplate().find(hql);
return ((Long) list.get(0)).intValue();
分享到:
相关推荐
非常详细直接实用的HQL语句的功能介绍 看过的人保准都说好
HQL语句大全HQL语句大全HQL语句大全HQL语句大全HQL语句大全
hql语句大全hql语句大全hql语句大全hql语句大全hql语句大全hql语句大全hql语句大全hql语句大全hql语句大全hql语句大全hql语句大全hql语句大全hql语句大全hql语句大全hql语句大全hql语句大全hql语句大全
HQL语句 HQL语句 HQL语句 HQL语句 HQL语句
解析内容清晰简单,让你对hql语句半天就可以掌握!!
hibernate-HQL语句大全
HQL语句的语法,很基础
主要是一些常用的HQL语句的使用与说明。
HQL语句大全
hql语句大全
下面介绍HQL语句的语法 1.from子句 2.select子句 3.聚集函数 4.多态查询 5.where子句 6.表达式 7.order by子句 8.group by子句 9.子查询语句 10.fetch关键字 11.命名查询
常见HQL语句的示例包括输出结果,以及语句的分析总结
汇集了hql语句中大部分常用的函数 ABS(n) 取绝对值数学函数 数学函数 JPAQL HQL ABS(column_name[数字类型对象属性])
HQL语句的用法,关于HQL与SQL语句的比较及其用法。
常用的HQL语句,包括增加,删除,修改,查询
hql语句常规 方法 使用 了解hql语句
HQL语句(结合实例)HQL语句(结合实例)HQL语句(结合实例)HQL语句(结合实例)HQL语句(结合实例)
HQL语句查询
HQL语句(结合实例).doc HQL语句(结合实例).doc HQL语句(结合实例).doc
整理的hql语句 id生成策略 集合传参,传参方式等 应有尽有