You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by "Jean-Louis Monteiro (Jira)" <ji...@apache.org> on 2022/01/19 10:12:00 UTC

[jira] [Commented] (TOMEE-3816) Return "this" on stateless EJB method looses container transaction management

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

Jean-Louis Monteiro commented on TOMEE-3816:
--------------------------------------------

Yes, this is expected.
When you use @Inject or @EJB or a JNDI lookup, TomEE gives you a proxy.

TomEE uses the proxy returned to implement an invocation chain for transactions, security, pool (stateless) and all sorts of EE features.

When you return this, you get your bean instance only.

> Return "this" on stateless EJB method looses container transaction management
> -----------------------------------------------------------------------------
>
>                 Key: TOMEE-3816
>                 URL: https://issues.apache.org/jira/browse/TOMEE-3816
>             Project: TomEE
>          Issue Type: Bug
>          Components: TomEE Build
>    Affects Versions: 8.0.8
>         Environment: TomEE 8.0.8, MS Windows 10, OpenJDK 15
>            Reporter: Makkus B.
>            Priority: Minor
>
> I experienced the following confusing behaviour in Tomee/OpenEjb when trying to construct a builder pattern with a @stateless session bean. When I return "this" from a builder pattern method, container managed transaction seemst to get lost. E.g a call to an EntityManagers persist() method, will throw a TransactionRequiredException.
> For reproduction figure this ejb (pseudocode):
> {{{}@Stateless{}}}{{{}class MyEjb {{}}}{{{{}}{}}}{{{}@PersistenceContext{}}}
> {{EntityManager em;}}
> {{public MyEjb getMe(){}}
> {{doSomeInternals();}}
> {{return this;}}
> {{}}}
> {{public void createSomething(){}}
> {{em.persist(new SomeEntity());}}
> {{}}}
>  
> in some client, if I call:
> {{myEjb.createSomething()}}
> the entity is created and stored. However, when I call
> {{myEjb.getMe().createSomething();}}
> the TransactionRequiredException is thrown.
>  
> Question:
> Is this an intended behavior? (I couln'd find any documentation in EJB why this would not be allowed to do. )
>  
>  
>  



--
This message was sent by Atlassian Jira
(v8.20.1#820001)