Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Theoretically, the issue is exactly the same: entity will become detaches when they leave the EJB unless something keeps the scope of the EntityManager open. (Here is a great post about the topic in general: <a href="http://blog.xebia.com/2009/04/27/jpa-implementation-patterns-lazy-loading/" rel="nofollow noreferrer">JPA implementation patterns: Lazy loading</a>).</p> <p>From a <a href="http://nurkiewicz.blogspot.com/2009/08/10-reasons-why-i-dont-like-ejb3.html" rel="nofollow noreferrer">blog post</a> I read:</p> <blockquote> <p><strong>8) No Open Entity Manager In View support.</strong> [...] In EJB3, when your entity leaves bean with <strong>transaction scoped</strong> EntityManager, it is detached from persistence context and you may no longer rely on lazy loading (in fact, JPA specification does not specify the behavior in such situation, probably some vendor dependent exception will be thrown...) Of course, you may use EntityManager with <strong>extended persistence context</strong>, holding the transaction and persistence context as long as you want. But this feature is only available for SFSB, while DAO classes are typical examples of stateless services, since they only dispatch calls to the persistence layer. Additionally, having dedicated DAO bean instance for each client seems to be a big overkill.</p> </blockquote> <p>I'm however not sure it is really true. From my understanding you should be able to write a servlet filter which uses the <a href="http://www.apache-korea.org/cactus/api/framework-13/javax/transaction/UserTransaction.html" rel="nofollow noreferrer"><code>UserTransaction</code></a> to start and commit the transaction (like the regular filter in OSIV). EJB would then participate in the transaction started in the filter and the <code>EntityManager</code> would remain open. I haven't tested it though, but my suggestion would be to give it a try.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload