-
Notifications
You must be signed in to change notification settings - Fork 5.1k
CAMEL-18377: camel-jpa - resue an EntityManager from the current tran… #8141
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
Conversation
|
|
|
❌ Finished component verification: 1 component(s) test failed out of 1 component(s) tested |
|
✔️ Finished component verification: 0 component(s) test failed out of 1 component(s) tested |
| } | ||
|
|
||
| // then try to reuse one from the current transaction if possible | ||
| if (em == null && TransactionSynchronizationManager.hasResource(entityManagerFactory)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not good to reuse the one from JpaTransactionManager. I just wonder if there is any way to reuse one in current transaction
if (em == null && exchange != null && exhange.isTransacted()) {
// get em from the transaction context in camel?
}@davsclaus any thoughts here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When the splitter creates sub exchanges it copies from the parent.
To reuse the same transaction manager, then we could
- Add a constant for this in Exchange (so its in core)
- Copy over the existing TM in the sub exchange if its transacted (in the splitter) (see link below)
- There are other EIPs that should do as 2 (Multicast, Recipient List, Enricher) but not wiretap
camel/core/camel-core-processor/src/main/java/org/apache/camel/processor/Splitter.java
Line 231 in 991f9ca
| newExchange.adapt(ExtendedExchange.class).setTransacted(original.isTransacted()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @davsclaus - I'm thinking to share an EntityManager in the sub exchanges during the transaction. Can you take a review about the changes in Splitter.java? If it's OK, I will apply the same change to other EIPs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes I added some comments see below
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I add the similar changes to multicast and recipientList processors. Aslo an unit test has been added to test with a pooling data source. For enrich, the default aggreate stragtegy is using the new exchange, so it works with transacted. But if the custom aggregate stragtegy is used, the users have to copy JpaConstants.ENTITY_MANAGE propery from the newExchange by themseleves. I also provide JpaHelper.copyEntityManagers method to do this copying.
core/camel-core-processor/src/main/java/org/apache/camel/processor/Splitter.java
Outdated
Show resolved
Hide resolved
|
✔️ Finished component verification: 0 component(s) test failed out of 2 component(s) tested |
|
✔️ Finished component verification: 0 component(s) test failed out of 1 component(s) tested |
|
❌ Finished component verification: 1 component(s) test failed out of 1 component(s) tested |
|
✔️ Finished component verification: 0 component(s) test failed out of 1 component(s) tested |
#8141) * CAMEL-18377: camel-jpa - reuse an EntityManager in the current transaction if possible * Fix to create txData only if the exchange is transacted * Add a unit test with pooling dataSource for transactd() combined with split() * Fix in multicast * Fix in RecipientList * Add a Enrich test * Fix CS
…saction if possible