Skip to content

Inconsistent JPA behavior using no transaction, propagation SUPPORTS and OpenEntityManager pattern [SPR-13243] #17834

@spring-projects-issues

Description

@spring-projects-issues

Andreas Benneke opened SPR-13243 and commented

We are using JPA (Hibernate 4) with Spring 4 managing the JTA transactions. To allow lazy initialization even when simply reading from the database without any transaction we added the "OpenEntityManager" pattern.

We know that there is a difference between having no transaction synchronization at all and SUPPORTS synchronization. But the JPA behaviour seems to be inconsistent somehow:

  • If there is no transaction synchronization active, we get a TransactionRequiredException from Springs SharedEntityManagerCreator when trying to persist something using JPA.
  • If there is only a SUPPORTS transaction synchronization active, we don't get this exception and the persist request is silently ignored. This however is exactly the situation to avoid in the SharedEntityManagerCreator when creating the above exception.
  • If there is an "OpenEntityManager" pattern active, there is no exception also and the persist request is silently ignored as well.

In my opinion there is no real difference between these situations and I would expect to see this exception in all cases or none?

You can find a test case for these questions on GitHub https://github.com/abenneke/sandbox/tree/master/spring-hibernate4-transaction


Affects: 4.1.7

Reference URL: http://stackoverflow.com/questions/27346975

Issue Links:

Referenced from: commits 7e2a662, fca33f5

0 votes, 5 watchers

Metadata

Metadata

Assignees

Labels

in: dataIssues in data modules (jdbc, orm, oxm, tx)type: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions