I have the following named query:

@NamedQueries({
@NamedQuery(name ="Movies.findByTitle", query = "SELECT m FROM Movies m WHERE m.title = :title")
})  

When I try to execute it as follows:

public List<T> findByTitle(String title) {
        return getEntityManager().
createNamedQuery("Movies.findByTitle").
setParameter("findByTitle", title).
getResultList();
    }

Then I get the following exception:

You have attempted to set a parameter value using a name of findByTitle that does not exist in the query string SELECT m FROM Movies m WHERE m.title = :title.

How is this caused and how can I solve it?

1

There are 1 best solutions below

0
Rambler On

You need to set a correct parameter name. You can see in your query the parameter is named "title" not "findByTitle".

setParameter("findByTitle", title) change this to setParameter("title", title)