title: How to use @NamedQuery in spring a CrudRepository @Query?
body: <p>I want to make use of a <code>@NamedQuery</code> inside a <code>JpaRepository</code>. But it does not work:</p>
  
  <pre><code>public interface MyEntityRepository extends JpaRepository&lt;MyEntity, Long&gt; {
      @Query(name = MyEntity.FIND_ALL_CUSTOM)
      List&lt;MyEntity&gt; findAllCustom(Pageable pageable);
  }
  
  @Entity
  @NamedQuery(
      name = MyEntity.FIND_ALL_CUSTOM, query = "select * from MyEntity me where me.age &gt;= 18"
  )
  public class MyEntity {
      public static final String FIND_ALL_CUSTOM = "findAllCustom";
  }
  </code></pre>
  
  <p>Result:</p>
  
  <pre><code>org.springframework.data.mapping.PropertyReferenceException: No property findAllCustom found for type MyEntity!
      at org.springframework.data.mapping.PropertyPath.&lt;init&gt;(PropertyPath.java:75)
      at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:327)
      at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:307)
      at org.springframework.data.mapping.PropertyPath.from(PropertyPath.java:270)
      at org.springframework.data.mapping.PropertyPath.from(PropertyPath.java:241)
      at org.springframework.data.repository.query.parser.Part.&lt;init&gt;(Part.java:76)
      at org.springframework.data.repository.query.parser.PartTree$OrPart.&lt;init&gt;(PartTree.java:235)
      at org.springframework.data.repository.query.parser.PartTree$Predicate.buildTree(PartTree.java:373)
      at org.springframework.data.repository.query.parser.PartTree$Predicate.&lt;init&gt;(PartTree.java:353)
      at org.springframework.data.repository.query.parser.PartTree.&lt;init&gt;(PartTree.java:84)
      at org.springframework.data.jpa.repository.query.PartTreeJpaQuery.&lt;init&gt;(PartTreeJpaQuery.java:61)
      at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$CreateQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:94)
      at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$CreateIfNotFoundQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:205)
      at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$AbstractQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:72)
      at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.&lt;init&gt;(RepositoryFactorySupport.java:369)
      at org.springframework.data.repository.core.support.RepositoryFactorySupport.getRepository(RepositoryFactorySupport.java:192)
      at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.initAndReturn(RepositoryFactoryBeanSupport.java:239)
      at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.afterPropertiesSet(RepositoryFactoryBeanSupport.java:225)
      at org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean.afterPropertiesSet(JpaRepositoryFactoryBean.java:92)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1633)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1570)
      ... 28 more
  </code></pre>
  
  <hr>
  
  <p>Update:</p>
  
  <pre><code>public interface MyEntityRepository extends JpaRepository&lt;MyEntity, Long&gt; {
      List&lt;MyEntity&gt; findAllCustom(Pageable pageable);
  }
  
  @Entity
  @NamedQuery(
      name = "MyEntity.findAllCustom", query = "select * from MyEntity me where me.age &gt;= 18"
  )
  public class MyEntity {
  
  }
  </code></pre>
  
  <p>Still same exception:</p>
  
  <pre><code>PropertyReferenceException: No property findAllCustom found for type MyEntity!
  </code></pre>