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()
.
If I manually call entityManager.joinTransaction()
it works, but that's surely not meant to be the solution.
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
:
ID of saved entity: null
If you include Hibernate and exclude EclipseLink, it works:
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.
Any help is very much appreciated.
Add
eclipselink.ddl-generation: drop-and-create-tables
to your JPA properties (otherwise the GREETING table doesn'† exist),
and add
@Bean
public PlatformTransactionManager transactionManager(EntityManagerFactory emf) {
return new JpaTransactionManager(emf);
}
to your EclipseLinkNoTransactionApplication class.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.