• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

org.hibernate.QueryException: Expected positional parameter

 
san krish
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Bartender
Posts: 1682
7
Android IntelliJ IDE Linux Mac OS X Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic