wood burning stoves 2.0*
The moose likes Object Relational Mapping and the fly likes org.hibernate.QueryException: Expected positional parameter Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "org.hibernate.QueryException: Expected positional parameter" Watch "org.hibernate.QueryException: Expected positional parameter" New topic

org.hibernate.QueryException: Expected positional parameter

san krish
Ranch Hand

Joined: Aug 11, 2010
Posts: 41
I have a namedQuery through which I pass 2 parameters like below,

ArrayList idName= new ArrayList();
idName.add(id); --int
idName.add(ABC); --Stringand I pass this object to namedQuery as follows:

return getHibernateTemplate().findByNamedQuery("findIDAndName", idName);and my hbm.xml has this query,

<sql-query name="findIDAndName">
<return alias="IdNamePmt" class="com.app.Grp.model.IdNamePmt"/>
<![CDATA[select * from PMT.CSE_NME_VW where PMT_ID=? and PMT_NAME=?]]>
</sql-query>When i run the application I get the below error:

org.hibernate.QueryException: Expected positional parameter count: 2, actual parameters: [[7, ABC]] [select * from PMT.CSE_NME_VW where PMT_ID=? and PMT_NAME=?]
at org.hibernate.impl.AbstractQueryImpl.verifyParameters(AbstractQueryImpl.java:367)
at org.hibernate.impl.SQLQueryImpl.verifyParameters(SQLQueryImpl.java:228)
at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:172)I have passed 2 parameters and my 'where' clause also expects 2 parameters. What is wrong? any
Bill Gorder

Joined: Mar 07, 2010
Posts: 1650

Use of hibernate template is discouraged now. See the Spring documentation for the preferred approach. The constructor for findByNamedQuery expects an Object array not an ArrayList. The array list you are passing in is being treated as a single object value.

[How To Ask Questions][Read before you PM me]
GeeCON Prague 2014
subject: org.hibernate.QueryException: Expected positional parameter