org.hibernate.QueryParameterException: could not locate named parameter

When you query the database in Hibernate using NamedQuery you may run into this error

org.hibernate.QueryParameterException: could not locate named parameter [parm1]

Chances are that you are either trying to set a parmeter to the query which infact doesn’t exist in your query. For example

you are trying to do

query.setParameter(“parm1”, new Long(parm1Value));

whereas, in query there is no parameter like parm1

i.e. query might be just “from Item item”

Or you might be committing some spelling mistake in your code

Eg. query.setParameter(“pram1”, new Long(parm1Value));

and query is “from Item item item.desc like :parm1”

Do note that your parameter name in Java Class is misspelt as pram1 instead of parm1.

5 thoughts on “org.hibernate.QueryParameterException: could not locate named parameter

  1. Pingback: 2010 in review « Techspace

Leave a Reply

Your email address will not be published. Required fields are marked *