简体   繁体   English

没有使用Spring / EclipseLink的EntityManager事务

[英]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.

相关问题 Spring 使用 EclipseLink 处理事务 - Spring Transaction handling with EclipseLink 为什么在春季交易中EntityManager为null? - why EntityManager is null in spring transaction? 方法完成时,Spring EntityManager提交事务 - Spring EntityManager Commit Transaction as method completes 使用Spring手动交易管理获取EntityManager - Get EntityManager using spring manual transaction management 如何在 Spring 中的共享 EntityManager 上手动启动事务? - How to manually start a transaction on a shared EntityManager in Spring? 覆盖EclipseLink EntityManager - Overriding EclipseLink EntityManager Spring ORM JNDI Tomcat-没有具有实际交易的EntityManager - Spring ORM JNDI Tomcat - No EntityManager with actual transaction available 基于Java配置的Spring Data CrudRepository-EntityManager-正在进行任何事务 - Spring Data CrudRepository on java based configuration - EntityManager - no transaction is in progress 在Spring中使用JPA EntityManager和Hibernate会话与共享事务管理器 - Using both JPA EntityManager and Hibernate session with shared transaction manager in Spring 使用 Java Spring 和 Hibernate 和 EntityManager 的 @Transactional 方法中的事务提交问题 - Problem with transaction commit in @Transactional methods using Java Spring and Hibernate and EntityManager
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM