Techspace

IT happens only in IT

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

January 8, 2008 - Posted by | Hibernate | , ,

4 Comments »

  1. this very useful for beginners..thanks

    Comment by siva | February 26, 2009 | Reply

  2. also make sure you didn’t write ‘createNativeQuery’ instead of ‘createNamedQuery’ by accident :)

    Comment by Gabor Farkas | August 6, 2009 | Reply

  3. or, also make sure you didn’t write ‘findByNamedQuery’ instead of ‘findByNamedQueryAndNamedParams’

    Comment by Neno | October 18, 2010 | Reply

  4. [...] 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 | Reply


Leave a Reply

Fill in your details below or click an icon to log in:

Gravatar
WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.