我正在向现有项目中添加代码,并且更喜欢将JPA / entityManager与Hibernate ORM一起使用。我添加了新的配置项:
hibernateJpaVendorAdapter
entityManagerFactory
persistenceAnnotationBeanPostProcessor
sharedEntityManagerBean (as EntityManager bean)
jpaTransactionManager (primary="false")
jpa:repositories
tx:annotation-driven (transaction-manager="jpaTransactionManager")
我在原始的transactionManager中添加了primary = true,以希望不必在所有原始的@Transactional注释中添加transactionManager参数。在新代码中,我声明了:
@Transactional(transactionManager = "jpaTransactionManager")
在控制器,中间层和DAO类上。但是,当调用JPA代码读取或保存数据时,会发生以下错误:
Invocation of init method failed; nested exception is javax.persistence.TransactionRequiredException: no transaction is in progress
由于我没有更改原始代码,所以我不知道为什么现在会发生这种情况?