[ 
https://issues.apache.org/jira/browse/ARIES-1346?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14615179#comment-14615179
 ] 

Michał Woś commented on ARIES-1346:
-----------------------------------

True. I can workaround this issue by injecting EM in a rest service class but 
considering I have over 40 rest service classes using different units 
(unitName), the amount of code to update is too significant. I will wait till 
next release.

Coordination API sounds good. It leaves separation between transaction an 
entity manager injection. What should be considered is JTA transaction. Some of 
EMs can handle JTA whereas in other cases we need multiple EM to handle 
multiple persistence units. E.g. eclipselink has EM that handle multiple units.
{code}
<property name="eclipselink.composite-unit" value="true"/>
{code}

> EntityManager injection issue
> -----------------------------
>
>                 Key: ARIES-1346
>                 URL: https://issues.apache.org/jira/browse/ARIES-1346
>             Project: Aries
>          Issue Type: Improvement
>          Components: JPA
>    Affects Versions: jpa-2.0.0
>         Environment: karaf-4.0.0, java 8
>            Reporter: Michał Woś
>            Priority: Critical
>
> Consider scenario:
> - blueprint service A with JPA 
> {code}
>    A {
>       C find() {
>          return em.find();
>       }
>       void delete(C c) {
>          em.remove(c)
>       }
>   }
> {code}
> - blueprint  bean B with A injected. B call methods of A within transaction
> {code}
> B {
>    @Transaction
>    B1() {
>       C = A.find(); // Entity returned by find (em.find())
>       A.delete(C); // Entity is not attached!!!!!!
>    }
> }
> {code}
> Reason:
> Method of bean A are proxied in following way:
> {code}
> emsupplier.precall()
> emsupplier.get()
> find(); //or delete()
> emsupplier.postcall()
> {code}
> Each method call gets its own EM so find has one EM, delete has another one. 
> Entity C is managed within first EM but not the second.
> EM should be shared in transaction within single Thread, not by single method 
> call.
> Please also note that:
> - transaction could be JTA and use different units in single transaction
> My scenario:
> - bundle A1,A2,A3 with persistence JPA exposing entities through services 
> (domain module), Each bundle (A1, A2, A3) uses different schema in database 
> (different unit name)
> - bundle B1,B2,B3 with rest  services using entity services in a transaction
> (Separation of domain logic from business logic). Each of B1,B2,B3 can use 
> any method of A1,A2,A3



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to