Description
Alexandru-Constantin Bledea opened SPR-16162 and commented
One case that I keep coming across every once in a while is the issue that was described in #19524.
So I basically want to reopen that case but with an improvement suggestion rather than a bug report.
The problem as described there was that "The underlying technical problem is that we can't influence Hibernate's connection release mode depending on the transaction setup: simply because JPA doesn't allow us to reliably introspect the transaction setup in general."
I've dug a bit into this and I'm wondering why we need to know the transaction manager at the point of creating the JpaVendorAdapter? The JpaVendorAdapter is only used for the EntityManagerFactory and when we are building the EntityManagerFactory we do know what transaction type we will be using. This information is available from the JPA PersistenceUnitInfo.
I'm thinking if it would make sense to add an additional method to JpaVendorAdapter, something like, getAdditionalJpaPropertiesMapByTransactionType() that is called after the default getJpaPropertiesMap method. That way we can selectively enrich the properties of one transaction type or the other.
By separating the properties by transaction type, it would be possible to 'autoconfigure' the backwards compatibility with spring in standalone mode and also keep the backwards compatibility with the JTA configuration.
What do you think?
Affects: 4.3.6
Issue Links:
- Doc: HibernateJpaVendorAdapter's "prepareConnection" may interfere with Hibernate 5.1+ in a JTA environment [SPR-14957] #19524 Doc: HibernateJpaVendorAdapter's "prepareConnection" may interfere with Hibernate 5.1+ in a JTA environment
Referenced from: pull request #1591
Backported to: 4.3.13