[英]No EntityManager transaction with Spring/EclipseLink
In my Spring Data JPA application, I switched from Hibernate to EclipseLink only to find out that now the EntityManager instances are not part of the transactions anymore, and therefore no data gets inserted when calling persist()
. 在我的Spring Data JPA应用程序中,我从Hibernate切换到EclipseLink只是为了发现EntityManager实例不再是事务的一部分,因此在调用persist()
时不会插入任何数据。
If I manually call entityManager.joinTransaction()
it works, but that's surely not meant to be the solution. 如果我手动调用entityManager.joinTransaction()
它可以工作,但这肯定不是解决方案。
I created a sample project that allows reproducing the problem: https://github.com/micheljung/eclipselink-no-transaction Pay attention to how it does not print an INSERT statement in the console, and how the ID of the saved entity stays null
: 我创建了一个示例项目,该项目允许重现该问题: https : //github.com/micheljung/eclipselink-no-transaction请注意它如何在控制台中不打印INSERT语句,以及保存的实体的ID如何保留null
:
ID of saved entity: null
If you include Hibernate and exclude EclipseLink, it works: 如果包含Hibernate并排除EclipseLink,则可以使用:
Hibernate: insert into greeting (id, greeting) values (null, ?)
ID of saved entity: 1
I already spent the last 3h reading all related Blogs and SO posts, but none of the results revealed any problem. 我已经花了最后3小时阅读所有相关的Blog和SO帖子,但是所有结果都没有发现任何问题。
Any help is very much appreciated. 很感谢任何形式的帮助。
Add 加
eclipselink.ddl-generation: drop-and-create-tables
to your JPA properties (otherwise the GREETING table doesn'† exist), 到您的JPA属性(否则GREETING表不存在†),
and add 并添加
@Bean
public PlatformTransactionManager transactionManager(EntityManagerFactory emf) {
return new JpaTransactionManager(emf);
}
to your EclipseLinkNoTransactionApplication class. 到您的EclipseLinkNoTransactionApplication类。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.