3 ways of hibernate query

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: query to add field text, when the field text is empty, use the field name
    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: query to add field text, when the field text is empty, use the field name
List<Map<String,Object >> columns = this.systemService.findHql(hql, autoFormDbId);


3.DetachedCriteria

CriteriaQuery cq = new CriteriaQuery(WeixinTemplateSendResEntity.class, dataGrid);
//Add foreign key association table and use id to associate
cq.createAlias("weixinTemplateContentEntity" , "weixinTemplateContentEntity");

//or query
  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();

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326516484&siteId=291194637