- Query query = session.createQuery("from Article a where a.visible=?");
- query.setParameter(1, true);
<span style="font-size: x-small;"><span style="color: #008000;">Query query = session.createQuery("from Article a where a.visible=?");
query.setParameter(1, true);</span></span>
说明JPA下 索引是从1开始。
而在继承HibernateDaoSupport中的类里,若从1开始则出现以下异常:
- java.lang.IndexOutOfBoundsException: Remember that ordinal parameters are 1-base!
<span style="font-size: x-small;"><span style="color: #008000;">java.lang.IndexOutOfBoundsException: Remember that ordinal parameters are 1-base!</span></span>
因此要从0开始,正确如下:
- Query query = session.createQuery("from Article a where a.visible=?");
- query.setParameter(0, true);
--转自
该贴由koei123转至本版2015-7-26 22:50:08