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();
这个是在spring下面的哦,害怕有人看不明白,主要是我知道就行了,嘿嘿
转自:http://hi.baidu.com/lirong1978/blog/item/ed74a251b29edd1e367abe99.html
分享到:
相关推荐
非常详细直接实用的HQL语句的功能介绍 看过的人保准都说好
Spring中常用的hql查询方法_(getHibernateTemplate())
主要是一些常用的HQL语句的使用与说明。
hql语言中的一些常用的方法hql语言中的一些常用的方法hql语言中的一些常用的方法
HQL常用函数
解析内容清晰简单,让你对hql语句半天就可以掌握!!
汇集了hql语句中大部分常用的函数 ABS(n) 取绝对值数学函数 数学函数 JPAQL HQL ABS(column_name[数字类型对象属性])
常用的HQL语句,包括增加,删除,修改,查询
本人的学习笔记,记录的很详细。对于hql初学者来说是一份不可多得的学习资料。
适合大数据初学者,数据分析行业工作者登需要使用hive SQL的人使用
常用的HQL语句,准轻松掌握。一学就会,一看就懂。
总结的hql的语句的常用的增删改查,自己留着看的
Spring中常用的HQL查询方法,用户可以从里面学到在spring中学习hql
01. Hive基本概念 02. Hive架构 03. Hive数据组织 04. 常用HQL介绍
讲解用HQL语法操作数据库的常用方法,帮助你熟练HQL的应用
自己总结的代码,里面包括了几种最常用的方法
hql中常用函數介紹,hql的查询的常用函数的说明
基本上包含了HQL常用的所有类型的语句了
HQL :是面向对象的查询语言,同SQL有些相似是Hib中最常用的方式。 查询设定各种查询条件。 支持投影查询,检索出对象的部分属性。 支持分页查询,允许使用having和group by 提供内制的聚集函数,sum(),min(),max...
hive常用的开发规范 hdfs hbase udf函数 hql shell脚本开发等常用规范,仅供参考