在模糊查询时,如果使用到了的条件包括"_",在查询时,需要使用到转义字符对"_"进行转义,具体详细看下列代码:
name=name.replaceAll("\\_", "\\\\\\\\_");
final String _name = name;
List<Integer> cuIdList = super.getHibernateTemplate().execute(new HibernateCallback<List<Integer>>() {
@SuppressWarnings("unchecked")
@Override
public List<Integer> doInHibernate(Session session) throws HibernateException, SQLException {
StringBuffer sql = new StringBuffer(200);
sql.append("select ")
.append("c.id")
.append(" from s c ")
.append("where c.control_unit_id in(:controlUnitId)")
.append(" and c.name like '%")
.append(_name)
.append("%' ESCAPE '\\\\'");
SQLQuery query = session.createSQLQuery(sql.toString());
query.setParameterList("controlUnitId", unitIdWithPrivilege);
return query.list();
}
});
分享到:
相关推荐
Hibernate HQL查询 分页查询 模糊查询.docxHibernate HQL查询 分页查询 模糊查询.docxHibernate HQL查询 分页查询 模糊查询.docxHibernate HQL查询 分页查询 模糊查询.docxHibernate HQL查询 分页查询 模糊查询....
Hibernate-Criteria 模糊查询。介绍各种模糊查询的方法。
使用hibernate实现的分页效果 orm 映射 session 等技能点 带有注释和案例演示 表生成语句
Hibernate-Criteria_模糊查询
struts1.2 Hibernate 3 分页 模糊查询,希望对大家有用 pdf
Hibernate连表查询 Hibernate连表查询
hibernate多表联合查询实例,很经典的查询语句和总结.
总结的hql的查询,感觉很实用 已经写成.java格式,直接复制到项目中就能看了
hibernate实现动态SQL查询,通过XML配置SQL,FREEMARKER 解析,生成要执行的SQL
Hibernate 函数 ,子查询 和原生SQL查询。Hibernate 函数 ,子查询 和原生SQL查询
Hibernate 多表连接分页查询示范项目 Hibernate Criteria 多表连接 分页
Hibernate_QBC查询
struts+hibernate 整合实现模糊搜索
HQL是hibernate自己的一套查询
hibernate 多表查询 hibernate 多表不同于一般的sql嵌套查询,嵌套查询是不支持的,所以必须要配置好才能实现多表!只要配置好了,还是特别好用的
Nhibernate的模糊查询有需要的朋友可以看一下源码
hibernate 中HQL语句查询学习笔记