title: Spring boot 2.1 and Hibernate 5.3 SessionFactory not Autowired when annotating the Dao classes with @Repository
body: <p>When I am auto wiring  hibernate session factory in a Dao implementation annotated with @Repository spring annotation it fails to create the SessionFactory and Dao bean but, it works without the @Repository annotation.</p>
  
  <p>I search through lot of questions and answers but all are related to the earlier version of hibernate and spring boot like unwrap and create a session factory bean but all those methods are not compatible with spring-boot 2.1 and the latest Hibernate version.</p>
  
  <p>are there any specific method to create and autowired a hibernate session factory in spring boot 2.1 and latest hibernate versions(5.3)?</p>
  
  <pre><code>@Repository
  public class UserDaoImpl implements UserDao {
  
      @Autowired
      private SessionFactory sf;
  
      @Override
      public void addUser(User user) {
          Session session = sf.getCurrentSession();
          session.save(user);
      }
  
  
  }
  </code></pre>
  
  <p>in the above code SessionFactory auto-wired without @Repository and I create a config class with a bean as below</p>
  
  <pre><code>@Configuration
  public class DataConfig {
      @Bean
      public SessionFactory sessionFactory(@Autowired EntityManagerFactory factory) {
              if (factory.unwrap(SessionFactory.class) == null) {
                  throw new NullPointerException("factory is not a hibernate factory");
              }
              return factory.unwrap(SessionFactory.class);
      }
  
  }
  </code></pre>
  
  <p>It course "The dependencies of some of the beans in the application context form a cycle:" error</p>