AL-HADHRAMI.S7R
AL-HADHRAMI.S7R

Reputation: 1

Why does this JPQL fail with message "You have attempted to set a parameter at position x which does not exist in this query string"?

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?

Upvotes: 0

Views: 567

Answers (1)

Rambler
Rambler

Reputation: 5482

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)

Upvotes: 1

Related Questions