hibernate查询的3种方式

1.原生sql
this.jdbcTemplate.queryForObject(sql,Long.class);
Long orgNum = systemService
.getCountForJdbc("select count(1) from t_s_user_org where user_id = '" + u.getId() + "'");

String hasOperSql="SELECT operation FROM t_s_role_function fun, t_s_role_user role WHERE " +
"fun.functionid='"+functionId+"' AND fun.operation is not null AND fun.roleid=role.roleid AND role.userid='"+client.getUser().getId()+"' ";
//---author:jg_xugj----end-----date:20151210--------for:#781 【oracle兼容】兼容问题fun.operation!='' 在oracle 数据下不正确
List<String> hasOperList = this.systemService.findListbySql(hasOperSql);

2.hql

functionList = systemService.findHql("from TSFunction where functionType = ? ", (short)0);

//update-begin--Author: jg_huangxg Date:20151106 for:增加字段文本的查询,当字段文本为空时,使用字段名称
String hql = "select new Map(t.fieldName as fieldName,t.fieldText as fieldText) from AutoFormDbFieldEntity t where t.autoFormDbId=?";
//update-end--Author: jg_huangxg Date:20151106 for:增加字段文本的查询,当字段文本为空时,使用字段名称
List<Map<String,Object>> columns = this.systemService.findHql(hql, autoFormDbId);


3.DetachedCriteria

CriteriaQuery cq = new CriteriaQuery(WeixinTemplateSendResEntity.class, dataGrid);
//添加外键关联表,使用id进行关联
cq.createAlias("weixinTemplateContentEntity", "weixinTemplateContentEntity");

//or查询
Property age = Property.forName("age");

add( Restrictions.disjunction()

.add( age.isNull() )

.add( age.eq( new Integer(0) ) )

.add( age.eq( new Integer(1) ) )

.add( age.eq( new Integer(2) ) )

) )
//in查询
.add( Property.forName("name").in( new String[] { "Fritz", "Izi", "Pk" } ) )

.list();
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值