Hibernate模糊查询的一个问题
来源:互联网 发布:淘宝店铺欢迎语大全 编辑:程序博客网 时间:2024/05/20 13:13
from Project o where 1=1 and o.isDeleted=? and o.prjName like '%?%'; (对应以下(1))
在执行createQuery时没有问题,在为第一个参数赋值时也没有问题,但是就是为第二个参数赋值时总报错:
严重: java.lang.IndexOutOfBoundsException: Remember that ordinal parameters are 1-based!
javax.faces.el.EvaluationException: java.lang.IndexOutOfBoundsException: Remember that ordinal parameters are 1-based!
其实造成这个问题的根本原因还是对hibernate的使用不太了解,改成这样就没错了:from Project o where 1=1 and o.isDeleted=? and o.prjName like ?; query.setString(i, "%"+实际查询条件+"%"); 注意参数中第一个百分号的左边与第二个百分号的右边都没有单引号,这和平时写SQL语句是不同的,要特别关注一下。另外还应该了解一下俩点的区别
(1)HQL:from Project o where 1=1 and o.PRJ_NAME like '%strCond%';//这里PRJ_NAME 应该是数据库表中的实际字段名
HQL:from Project o where 1=1 and o.PRJ_NAME like '%strCond%';//这里PRJ_NAME 应该是实体类的属性名
(1)HQL:from Project o where 1=1 and PRJ_NAME like '?';//这里的?不视为占位参数
HQL:from Project o where 1=1 and PRJ_NAME like ?;//设置参数值时会自动在参数值两边加上单引号。
- Hibernate模糊查询的一个问题
- Hibernate模糊查询参数化的问题
- hibernate 模糊查询中查询条件包含单引号的问题
- 关于hibernate的模糊查询.
- 模糊查询的问题
- hibernate的模糊查询和sql查询
- 时间模糊查询一个很变态的问题!
- 一个WMI模糊查询引发的数据丢失问题
- hibernate模糊查询的几种方式
- 关于hibernate模糊查询的不足
- Hibernate实现模糊查询的方法
- Hibernate实现模糊查询的方法
- hibernate的hql模糊查询例子
- Hibernate NamedQuery like 模糊查询的写法
- Hibernate实现模糊查询的方法
- hibernate query 模糊查询
- Hibernate-Criteria 模糊查询
- Hibernate模糊查询参数
- Mysql日期函数
- 做一只墙上的苍蝇(a fly on the wall)
- linux 系统编码
- [双语阅读]正寻找爱情?试试身份徽章
- chmod 命令
- Hibernate模糊查询的一个问题
- shutdown,halt,reboot,init
- 学无止境
- 动员讲话 Pep talk
- base标签的属性target用法
- Left holding bag 背黑锅
- [英语阅读]意大利地震至少150人死亡
- HTML转义字符
- VG Conformance Test,Khronos的大杀器!