Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
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 Murach's Java Servlets and JSP this week in the Servlets 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: 1646

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]
It is sorta covered in the JavaRanch Style Guide.
subject: org.hibernate.QueryException: Expected positional parameter
Similar Threads
JPA native Query - Select... where... IN, How to set list of values to setParameter()?
Hibernate and DB2 stored procedure
@ManyToMany delete problem
Hibernate Query Language Question (simple)
org.hibernate.QueryException: Expected positional parameter count: 2, actual parameters: [1]