java.lang.ClassNotFoundException: org.hibernate.engine.transaction.spi.TransactionContext

前端 未结 6 1249
傲寒
傲寒 2021-02-19 06:02

I am developing Spring MVC Hibernate Integration example. In this example I\'m using Spring 4.1.9.RELEASE and Hibernate 5.1.0.Final. If I

6条回答
  •  忘掉有多难
    2021-02-19 06:51

    I wanted to create an application context that works well for both Hibernate 4 and Hibernate 5 at the same time.[why?]

    So I replaced Hibernate-specific transaction manager (org.springframework.orm.hibernate4.HibernateTransactionManager) with Spring JPA transaction manager (org.springframework.orm.jpa.JpaTransactionManager):

    // part of my Java Config
    @Bean
    @Autowired
    public JpaTransactionManager transactionManager(EntityManagerFactory entityManagerFactory, DataSource mainDataSource) {
        final JpaTransactionManager transactionManager = new JpaTransactionManager();
        transactionManager.setEntityManagerFactory(entityManagerFactory);
        transactionManager.setDataSource(mainDataSource);
        return transactionManager;
    }
    

    [why?] Because this context is shared between different modules that depend on different Spring and Hibernate versions.

提交回复
热议问题