I have the following named query:
@NamedQuery(
name = "Userdetails.findByUsername",
query = "SELECT u FROM Userdetails u WHERE u.username = :username"
)
When I try to execute it as follows:
getEntityManager()
.createNamedQuery("Userdetails.findByUsername")
.setParameter("string", "%" + string + "%")
.getResultList();
Then I get the following exception:
java.lang.IllegalArgumentException: You have attempted to set a parameter value using a name of string that does not exist in the query string SELECT u FROM Userdetails u WHERE u.username = :username.
How is this caused and how can I solve it?