title: No Query defined for that name, when using Entity Manager
body: <p>I have the following entity:</p>
  
  <pre><code>package com.server.models;
  @Entity
  @Table(name="users")
  @NamedQueries({
      @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";
      //  ...
  }
  </code></pre>
  
  <p>And then using the Entity Manager (em) i'm doing the following:</p>
  
  <pre><code>package com.server.controllers;
  @Service
  @Transactional
  @RestController
  @RequestMapping("/user")
  public class LoginController {
      @PersistenceContext
      private EntityManager em;
   // my code
      TypedQuery&lt;User&gt; queries = em.createNamedQuery(User.QUERY_FIND_USER,User.class).setParameter("username", username);
      List&lt;User&gt; users = queries.getResultList();
  }
  </code></pre>
  
  <p>However I am getting the following error:</p>
  
  <pre><code>java.lang.IllegalArgumentException: No query defined for that name [LoginFindUser]
  </code></pre>
  
  <p>Here's my spring-boot Configuration. This should include the scanning of the entity.</p>
  
  <pre><code>package com.server.boot;
  
  @Configuration
  @ComponentScan({"com.server"})
  @EnableAutoConfiguration
  public class Starter {
      public static void main(String[] args){
          SpringApplication.run(Starter.class,args);
          System.out.println("started application");
      }
  
      @Bean
      public LoginController loginController(){
          return new LoginController();
      }
  
      @Bean
      public HibernateJpaSessionFactoryBean sessionFactory(EntityManagerFactory emf) {
           HibernateJpaSessionFactoryBean factory = new HibernateJpaSessionFactoryBean();
           factory.setEntityManagerFactory(emf);
           return factory;
      }
  
  }
  </code></pre>