-
1. Re: Persistence context propagation.
pmuir May 30, 2006 12:06 PM (in response to iradix)I use Seam Managed EntityManager for this and it works as you suggest.
-
2. Re: Persistence context propagation.
gavin.king May 30, 2006 2:22 PM (in response to iradix)exactly
-
3. Re: Persistence context propagation.
iradix May 30, 2006 2:53 PM (in response to iradix)Hmm... This doesn't seem to be working the way I hoped it would. Let me explain in a bit more detail.
I would really rather not tie the SLSB DAOs to Seam so that they are as reusable between projects as possible, therefore they are using the plain vanilla @PersistenceContext annotation. When I invoke a DAO from a SFSB which contains a Seam managed EntityManager the persistence context does not seem to propagate as evidenced by the LazyInitializationException that I'm getting in the subsequent JSF page.
Since my stateful beans are almost always project specific I have no problem with using Seam enhancements within them. The DAOs are a different story though. Is there any way to mix and match the two types of persistence? -
4. Re: Persistence context propagation.
iradix May 30, 2006 3:04 PM (in response to iradix)Not sure if this is helpful or not, but the DAOs are injected using the @EJB annotation.
-
5. Re: Persistence context propagation.
gavin.king May 30, 2006 3:12 PM (in response to iradix)If you have a SFSB with an extended PC, and it calls a SLSB in the same JTA transaction, the extended PC will be propagated. (At least according to the EJB spec.)
I am the original author of these rules, so I'm pretty sure I remember correct ;-) -
6. Re: Persistence context propagation.
iradix May 30, 2006 3:28 PM (in response to iradix)I have no doubt that you are the man Gavin :) However is a seam managed entity manager considered an extended persistence context? What I've done to my code is to change:
@PersistenceContext(type=EXTENDED)
EntityManager entityManager;
to:
@In(create=true)
EntityManager entityManager;
along with the other relevant configuration for Seam managed persistence and now the persistence context does not appear to be propagating to the SLSBs. If it was I don't see how I could get the LazyInitializationException.
I have little doubt that I am either doing something wrong or not understanding something correctly, but I'm a bit stumped at the moment as to where I've gone wrong. -
7. Re: Persistence context propagation.
mangri3000 Aug 1, 2007 7:02 AM (in response to iradix)"iradix" wrote:
What I've done to my code is to change:
@PersistenceContext(type=EXTENDED)
EntityManager entityManager;
to:
@In(create=true)
EntityManager entityManager;
along with the other relevant configuration for Seam managed persistence and now the persistence context does not appear to be propagating to the SLSBs.
I experience exactly the same problem.
Is there a way to get the SMPC be propagated to SLSBs? -
8. Re: Persistence context propagation.
pmuir Aug 1, 2007 7:08 AM (in response to iradix)Any component within a conversation will have the same PC injected using @In.
-
9. Re: Persistence context propagation.
mangri3000 Aug 1, 2007 7:23 AM (in response to iradix)"pete.muir@jboss.org" wrote:
Any component within a conversation will have the same PC injected using @In.
I guess that requires that all my SLSB be seam components annotated with @Name.
I wouldn't like to do that with my DAO components (SLSBs).
Isn't it possible to attach the SMPC to the transaction (seam managed as well) and propagate it to my SLSB like an ordinary extended persistence context ? -
10. Re: Persistence context propagation.
pmuir Aug 1, 2007 7:47 AM (in response to iradix)Well you can't inject a SMPC into a non Seam component. Seam has no control over where @PersistenceContext comes from.
-
11. Re: Persistence context propagation.
christian.bauer Aug 1, 2007 8:40 AM (in response to iradix)Your DAOs can have a getPersistenceContext() method in which you do Component.getInstance("entityManager").
-
12. Re: Persistence context propagation.
mangri3000 Aug 1, 2007 11:12 AM (in response to iradix)I try to explain a little more.
Our system has two interfaces, a web-ui and a messaging based interface to another system.
Messaging requests come this way:
MessageController (MDB) -> Core (SLSB and Entities) -> DAOs (SLSBs) -> Hibernate
UI requests go the other way:
Web-UI -> Application (Seam components) -> Core -> DAOs -> Hibernate
DAOs use entity managers injected by "@PersistenceContext". I cannot use @In because otherwise the messaging scenario wouldn't work.
For messaging requests I need a transaction-scoped PC which I get for free by the default EJB PC propagation.
For the Web-Client requests I need a conversation-scoped PC. I thougth I could simply attach a SMPC or BMPC to every transaction (EntityManager.joinTransaction) in the application-layer and do not have to change the layers below.
Maybe there is not such a simple solution.