mangusbrother mangusbrother - 8 months ago 232
SQL Question

No Query defined for that name, when using Entity Manager

I have the following entity:

package com.server.models;
@NamedQuery(name=User.QUERY_FIND_USER,query="SELECT c FROM user c WHERE c.username = :username")
public class User {

public static final String QUERY_FIND_USER = "LoginFindUser";
// ...

And then using the Entity Manager (em) i'm doing the following:

package com.server.controllers;
public class LoginController {
private EntityManager em;
// my code
TypedQuery<User> queries = em.createNamedQuery(User.QUERY_FIND_USER,User.class).setParameter("username", username);
List<User> users = queries.getResultList();

However I am getting the following error:

java.lang.IllegalArgumentException: No query defined for that name [LoginFindUser]

Here's my spring-boot Configuration. This should include the scanning of the entity.

package com.server.boot;

public class Starter {
public static void main(String[] args){,args);
System.out.println("started application");

public LoginController loginController(){
return new LoginController();

public HibernateJpaSessionFactoryBean sessionFactory(EntityManagerFactory emf) {
HibernateJpaSessionFactoryBean factory = new HibernateJpaSessionFactoryBean();
return factory;



Found it. Thanks to the guys in the comments



to your configuration class

and I had an error in the query cause user needed to be User