title: I am getting this error org.springframework.orm.jpa.EntityManagerHolder cannot be cast to org.springframework.orm.hibernate5.SessionHolder
body: <p>I am trying to use hibernate with spring boot. But I am getting this error: 
  org.springframework.orm.jpa.EntityManagerHolder cannot be cast to org.springframework.orm.hibernate5.SessionHolder.
  I am a beginner trying to learn spring boot. Any help would be much appreciated.</p>
  
  <p>application.properties:</p>
  
  <pre><code>spring.datasource.url=jdbc:mysql://localhost:3306/userdetails
  spring.datasource.username=root
  spring.datasource.password=password
  spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
  hibernate.dialect = org.hibernate.dialect.MySQLDialect
  </code></pre>
  
  <p>Here is my configuration file:</p>
  
  <pre><code>@Configuration
  @PropertySource(value = "classpath:application.properties")
  public class EclinicReportBeanConfig {
  
      @Value("${spring.datasource.url}")
      private String url;
  
      @Value("${spring.datasource.username}")
      private String username;
  
      @Value("${spring.datasource.password}")
      private String password;
  
      @Value("${spring.datasource.driver-class-name}")
      private String driverClassName;
  
      @Value("${hibernate.dialect}")
      private String dialect;
  
      @Bean
      public DataSource getDataSource() {
          DriverManagerDataSource dataSource = new DriverManagerDataSource(url, username, password);
          dataSource.setDriverClassName(driverClassName);
          return dataSource;
      }
  
      @Bean
      public LocalSessionFactoryBean localSessionFactory() {
          LocalSessionFactoryBean factory = new LocalSessionFactoryBean();
          factory.setDataSource(getDataSource());
          factory.setHibernateProperties(hibernateProperties());
          factory.setPackagesToScan(new String[] { "com.eclinic.report" });
          return factory;
      }
  
      private Properties hibernateProperties() {
          Properties properties = new Properties();
          properties.put("hibernate.dialect", dialect);
          properties.put("hibernate.hbm2ddl.auto", "none");
          properties.put("hibernate.show_sql", "true");
          properties.put("hibernate.format_sql", "true");
          return properties;
      }
  
      @Bean
      @Autowired
      public HibernateTransactionManager transactionManager(SessionFactory factory) {
          HibernateTransactionManager transactionManager = new HibernateTransactionManager();
          transactionManager.setSessionFactory(factory);
          return transactionManager;
      }
  </code></pre>
  
  <p>Here is my dao file :</p>
  
  <pre><code>@Repository
  public class DHAReportDaoImpl implements DHAReportDao {
  
      @Autowired 
      private SessionFactory sessionFactory;
  
      @Override
      public List&lt;UserSetup&gt; getAllUserDetails() {
  
          String hql = "select userId, userName from UserSetup";
          Query&lt;UserSetup&gt; query = getSession().createQuery(hql);
          List&lt;UserSetup&gt; userlist = query.getResultList();
  
          return userlist;
      }
  
      private Session getSession() {
          Session session = sessionFactory.getCurrentSession();
          if (session == null) {
              session = sessionFactory.openSession();
          }
          return session;
      }
  
  }
  </code></pre>
  
  <p>My pom.xml dependencies:</p>
  
  <pre><code>    &lt;dependencies&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-data-jpa&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;mysql&lt;/groupId&gt;
              &lt;artifactId&gt;mysql-connector-java&lt;/artifactId&gt;
              &lt;scope&gt;runtime&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-configuration-processor&lt;/artifactId&gt;
              &lt;optional&gt;true&lt;/optional&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-devtools&lt;/artifactId&gt;
          &lt;/dependency&gt;
      &lt;/dependencies&gt;
  </code></pre>