-
Notifications
You must be signed in to change notification settings - Fork 38.5k
Make JpaVendorAdapters JTA-aware (in particular for Hibernate 5.1/5.2) [SPR-16162] #20710
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Juergen Hoeller commented Good point! Let's see what we can do there. |
Alexandru-Constantin Bledea commented Pull request here If the transaction type cannot be determined for whatever reason, we still override the connection release mode just to maintain the previous behavior, but I tested this with WebLogic and it identifies the JTA and all is good. To be honest, I'm wondering if it still makes sense to have two methods for the jpa properties. They're only used one after the other anyway, I'm thinking of merging them back and just adding the TransactionType parameter to the original method, what do you think? |
Juergen Hoeller commented Alright, this looks like a good start! I intend to approach the subclass/superclass interaction a bit differently, and indeed, we should merge the JPA properties access to a single method which takes the transaction type or maybe even the entire So I guess this back on the 5.0.2 roadmap for mid next week now :-) For the sake of timing, I'll spend some time on it right away this afternoon, inspired by your pull request. Just wondering: Can you consume that revision in 5.0.2? Or are you strictly bound to 4.3.x at this point? |
Alexandru-Constantin Bledea commented I performed the changes on 5.0.2 but it would be great if once this is implemented it would get backported to 4.3.x. I am quite happy to work with you to get this thing rolling, Just let me know how I can help and I will gladly do it. Just let me know how you want to proceed and I can try to support you the best that I can. |
Juergen Hoeller commented I've prepared a pass for master: Since we can't declare |
Alexandru-Constantin Bledea commented Sounds good. Also I think that the javadoc for prepareConnection should be updated to reflect the fact that now if Spring is able to determine that we're using JTA it backs off from overriding the connection release configuration which causes hibernate to pick what it considers the best strategy. |
Juergen Hoeller commented Good catch about the javadoc; revised now. A minor revision of the implementation approach above: Due to package interdependencies, downcasting to |
Alexandru-Constantin Bledea commented I tested the implementation in master and it skips configuring JTA for now. One thing I noticed is that now, if the transaction type is unknown, we are no longer overriding the default properties, was this intended? Also, I took a look into LocalEntityManagerFactory and I'm thinking that we could also try to get its persistence unit info to detect the transaction type with something like @Nullable
@Override
public PersistenceUnitInfo getPersistenceUnitInfo() {
DefaultPersistenceUnitManager pum = new DefaultPersistenceUnitManager();
pum.afterPropertiesSet();
return pum.obtainPersistenceUnitInfo(getPersistenceUnitName());
} Admittedly, I'm not sure if this persistence unit info will be 100% accurate because internally the PersistenceProvider has its own way of interpreting the persistence.xml file but at least for the transaction type (which is really the only thing that we care about at this point) should be accurate. What do you think? |
Juergen Hoeller commented Oops, I indeed missed the Fortunately, Having the mechanism generically extended to react to the |
Juergen Hoeller commented
|
Alexandru-Constantin Bledea commented I took a quick look over the backport of the improvement and i think that line 175 should be changed to use the connectionReleaseOnClose parameter Line 175 in d52d9fd
Update: I was looking at an older version, looks great in 4.3.x. Thank you! |
Juergen Hoeller commented Actually, your point seems valid: I accidentally skipped that line when merging. I've revised this in 4.3.x, so that check is in sync with master now. |
Alexandru-Constantin Bledea commented Hibernate specifies that AFTER_TRANSACTION release mechanism should never be used for JTA transactions in the case of application server managed datasource But the hibernate jta vendor adapter suggests that mode as a posibility in such cases. I'm wondering the suggestion should be removed to not get inconsistent behavior. |
Juergen Hoeller commented To the best of my experience, All in all, Hibernate's javadoc isn't as nuanced as it should be there. If broader reuse of connection handles works in your app server scenario, there's nothing wrong with it; it's generally recommendable to go with the broadest mode possible. You'll find out very quickly whether it works anyway - the app server will reject access to your connection if you're misusing it according to the platform's policies - and can easily downgrade to |
Alexandru-Constantin Bledea commented Good to know, I have read some articles suggested that AFTER_TRANSACTION is faster but I saw that hibernate suggests otherwise so I wasn't sure what the best approach is. I will try AFTER_TRANSACTION myself to see if I will notice some inconsistent behavior. Thanks. |
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:
Referenced from: pull request #1591
Backported to: 4.3.13
The text was updated successfully, but these errors were encountered: