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.
You can find a test case for these questions on GitHub https://github.com/abenneke/sandbox/tree/master/spring-hibernate4-transaction
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 SpringsSharedEntityManagerCreator
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?
Thank you!
Update July 2015: I now raised this as an issue to Spring https://jira.spring.io/browse/SPR-13243