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();
hibernate查询的3种方式
猜你喜欢
转载自lsh2366254.iteye.com/blog/2367597
今日推荐
周排行