CAMEL-18377: camel-jpa - resue an EntityManager from the current tran…#8141
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.
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.
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
There was a problem hiding this comment.
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.
Yes I added some comments see below
There was a problem hiding this comment.
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.
|
✔️ 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