关于Hibernate底层的查询处理(忽略大小写,模糊匹配,自动加载属性)
来源:互联网 发布:sql server教材 编辑:程序博客网 时间:2024/05/20 16:36
问题描述:Hibernate下做模糊匹配不区分大小写的时候,控制打印出来的脚本出现两个coornateName,明明我只传了一个,为什么会有两个?
①模糊匹配 like("属性",条件)
②忽略大小写 like("属性",条件).ignoreCase()
原因:HibrenateUtils.createDetachedCriteria(class,true) 会自动加载属性,也就是说只要action接收了属性对应的值,查询的时候,就会自动给该值做匹配(=)
原始脚本:
select this_.id as id24_0_, this_.axisId as axisId24_0_, this_.isLock as isLock24_0_, this_.addDate as addDate24_0_, this_.coordinateName as coordina5_24_0_, this_.PROCESSID as PROCESSID24_0_, this_.parentId as parentId24_0_, this_.coordinateValue as coordina8_24_0_, this_.isValid as isValid24_0_, this_.adduser as adduser24_0_ from t_coordinate this_ where this_.coornaditeName = ? <pre name="code" class="sql"><span style="white-space:pre"></span>and lower(this_.coordinateName) like ?and this_.axisId=? order by this_.addDate desc
然后把HibrenateUtils.createDetachedCriteria(class,true)换成DetachedCriteria.forClass(TCoordinate.class);
select this_.id as id24_0_, this_.axisId as axisId24_0_, this_.isLock as isLock24_0_, this_.addDate as addDate24_0_, this_.coordinateName as coordina5_24_0_, this_.PROCESSID as PROCESSID24_0_, this_.parentId as parentId24_0_, this_.coordinateValue as coordina8_24_0_, this_.isValid as isValid24_0_, this_.adduser as adduser24_0_ from t_coordinate this_ where this_.axisId=? and lower(this_.coordinateName) like ? order by this_.addDate desc
完整的java代码:
public Page getCoordByPage(Page queryHandler, TCoordinate conditions) {DetachedCriteria dc = DetachedCriteria.forClass(TCoordinate.class);if (conditions.getTAxis() != null) {dc.add(Restrictions.eq("TAxis", conditions.getTAxis()));}if(conditions.getCoordinateName()!=null){dc.add(Restrictions.like("coordinateName", conditions.getCoordinateName(),MatchMode.ANYWHERE).ignoreCase());}if(conditions.getParentCoordinate().getId()!=null){dc.add(Restrictions.eq("parentCoordinate.id", conditions.getParentCoordinate().getId()));}dc.addOrder(Order.desc("addDate"));Page page = this.coordinateDao.getPageByCriteria(queryHandler, dc);return page;}
模糊匹配,忽略大小写的关键代码:
dc.add(Restrictions.like("coordinateName", conditions.getCoordinateName(),MatchMode.ANYWHERE).ignoreCase());
0 0
- 关于Hibernate底层的查询处理(忽略大小写,模糊匹配,自动加载属性)
- SQL 忽略大小写模糊查询
- oracle 模糊查询忽略大小写
- oracle模糊查询忽略大小写
- oracle 模糊查询忽略大小写
- C# Xamarin.Parse 模糊查询 忽略大小写
- Oracle SQL忽略大小写模糊查询
- 关于hibernate的模糊查询.
- 关于hibernate模糊查询的不足
- 模糊查询——忽略大小写小技巧
- 忽略大小写匹配
- jQuery忽略大小写匹配
- MySQL忽略顺序的正则模糊匹配
- Dictionary 中忽略大小写的查询
- Oracle查询忽略大小写的实现方法
- Oracle查询忽略大小写的实现方法
- 首字母自动匹配与模糊查询
- 忽略大小写查询
- JAVA_OPTS设置
- DB2中设置当前会话的Schema
- 每天一个linux命令
- 经典的HaarTraining算法
- Callable和Future浅析
- 关于Hibernate底层的查询处理(忽略大小写,模糊匹配,自动加载属性)
- 关于mac80211
- 下雨天
- Tornado的url-handler映射中可以使用字符串
- android 的sqlite 主键与simpleCursorAdapter
- Valid Sudoku
- Java volatile详解
- 在父子进程间用管道传递文件描述符
- VMware Workstation CentOS6.3 minimal NAT模式上外网