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.
Advertisement
this very useful for beginners..thanks
also make sure you didn’t write ‘createNativeQuery’ instead of ‘createNamedQuery’ by accident
or, also make sure you didn’t write ‘findByNamedQuery’ instead of ‘findByNamedQueryAndNamedParams’
[...] Recent Comments Chittedi on Exact Target Client in JavaDevinder on generate-all No domain class found for.. error in grailsParas on Exact Target Client in JavaChittedi on Exact Target Client in JavaNeno on org.hibernate.QueryParameterException: could not locate named parameter [...]
Pingback by 2010 in review « Techspace | January 4, 2011 |