title: Generic Dao with Spring data
body: <p>I'm using Spring Data Repositories and custom Repositories on a Spring boot project, but I want to add Generic Repository for the customs.</p>
  
  <p>This is <code>GenericCustomRepositoy</code> : </p>
  
  <pre><code>public interface GenericCustomRepositoy&lt;T, ID&gt; {
  
      List&lt;T&gt; findByFields(Class&lt;T&gt; clazz, List&lt;Pair&lt;String, Object&gt;&gt; fieldValue, List&lt;Pair&lt;String, Boolean&gt;&gt; orderBy);
  }
  @Repository
  public class GenericCustomRepositoyImpl&lt;T, ID&gt; implements GenericCustomRepositoy&lt;T, ID&gt; {
  
      @PersistenceContext
      protected EntityManager em;
  
      public List&lt;T&gt; findByFields(Class&lt;T&gt; clazz, List&lt;Pair&lt;String, Object&gt;&gt; fieldValues, List&lt;Pair&lt;String, Boolean&gt;&gt; orderBy) {
  
          final CriteriaBuilder cb = em.getCriteriaBuilder();
          final CriteriaQuery&lt;T&gt; cq = cb.createQuery(clazz);
          final Root&lt;T&gt; root = cq.from(clazz);
  
          ........................
  
          return em.createQuery(cq).getResultList();
      }
  </code></pre>
  
  <p>This is My Repository :</p>
  
  <pre><code>@Repository
  public interface AdresseLivraisonRepository extends JpaRepository&lt;AddressEntity, Integer&gt;, GenericCustomRepositoy&lt;AddressEntity, Integer&gt; {
  
  }
  </code></pre>
  
  <p>I have this exception when i wont to run the application :</p>
  
  <pre><code>Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'adresseLivraisonRepository': Invocation of init method failed; nested exception is org.springframework.data.mapping.PropertyReferenceException: No property fields found for type AddressEntity!
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1628)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)
      at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
      at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
      at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
      at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
      at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:208)
      at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1138)
      at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1066)
      at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:585)
  </code></pre>
  
  <p>There is something I'm doing wrong!</p>
  
  <p>I changed my code and I added a custom repository that extends the Generic but I get the same exception.</p>
  
  <p>This is the new repository :</p>
  
  <pre><code>@Repository
  public interface AdresseLivraisonRepository extends JpaRepository&lt;ForwardingAddressEntity, Integer&gt;, AdresseLivraisonCustomRepository {
  
  }
  </code></pre>