This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
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

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
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=""/>
<![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(
at org.hibernate.impl.SQLQueryImpl.verifyParameters(
at org.hibernate.impl.SQLQueryImpl.list( have passed 2 parameters and my 'where' clause also expects 2 parameters. What is wrong? any
Bill Gorder

Joined: Mar 07, 2010
Posts: 1682

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]
I agree. Here's the link:
subject: org.hibernate.QueryException: Expected positional parameter
It's not a secret anymore!