-
1. Re: EJB3 Facade Design
bill.burke May 23, 2006 10:30 AM (in response to echon)I like your idea of a context, post on the seam dev forum about this. Seems there should be a transactional context that you can add/remove things from.
In the meantime, something you might want to think about:
@Stateful
public class MyBean ... {
@PersistenceContext(unitName="mypu", type=EXTENDED) myPC;
@EJB AnotherStateful nested;
}
@Stateful
public class AnotherStatefulBean implements AnotherStateful {
@PersistenceContext(unitName="myPU", type=EXTENDED) myPC;
}
----
Since MyBean.nested is injected into MyBean these two stateful beans are married to eachother and share the same lifecycle and same persistence contexts!
Bill -
2. Re: EJB3 Facade Design
echon May 23, 2006 11:04 AM (in response to echon)thx. for the realy quick answer.
So if i inject a EJB they share the same lifecycle and persistence context.
Matching this with the Context-Idea your MyBean represents a Context who knows about all other DAO StatefullBeans (your AnotherStatefulBean) like (UserDAO, GroupDAO, ... a lot more) which are automatically generated when the Context is created. I think this is a little bit inefficient.
Interesting would be the other side. When i want to have a GroupDAO from Factory by getGroupDAO(int contexttype), the factory looksup if the right Context exists (or create it) and then get a GroupDAO Stateful SB and tell it the context. To synchronize i have to call perhaps factory.flush(int contexttype) or factory.getContext(int contexttype).flush().
I also thought about Implementing the Context like a wrapper of ExtendedEntityManager and give it over to the dao.
Regards
Peter -
3. Re: EJB3 Facade Design
bill.burke May 23, 2006 11:09 AM (in response to echon)only injected nested SFSBs will share same lifecycle/pc. SLSBs only share PC if called in the same transaction.
-
4. Re: EJB3 Facade Design
echon May 23, 2006 11:42 AM (in response to echon)Is it possible to giveout the EntityManager of a STSB, if i have removed Container-Isolation or would this end in a HorribleException?
-
5. Re: EJB3 Facade Design
bill.burke May 23, 2006 11:48 AM (in response to echon)horrible exception or undefiend behavior.
-
6. Re: EJB3 Facade Design
bill.burke May 23, 2006 11:49 AM (in response to echon)you can also inject at @PersistenceUnit and create an entity from an EMF. This entity manager would be extended.
-
7. Re: EJB3 Facade Design
echon May 24, 2006 7:01 AM (in response to echon)It is really not possible to share an EntityManager between SFSB, or would this be only a problem if clustering?
So the conclusion would be something like a Command-Pattern, where
the Context SFSB is the Command "Executor" who has an EntityManager and my DAOs only create Command Implementations and transfer them to the Context SFSB?
Regards
Peter -
8. Re: EJB3 Facade Design
echon May 24, 2006 7:06 AM (in response to echon)to continue this example..
With this idea i would have a Contexts-Object with LocalThread attributes (Context is a SFSB) which are initialized via a ServletFilter who
gets the Context from ServletContext, ServletSession and creates a new for the Request Context. Furthermore i have a SessionListener and ApplicationListerner who creates Context SFSB for Session and Application Context. -
9. Re: EJB3 Facade Design
echon May 24, 2006 8:23 AM (in response to echon)Something additional to
Since MyBean.nested is injected into MyBean these two stateful beans are married to eachother and share the same lifecycle and same persistence contexts!"
If they were injected or also if i get them from JNDI in my Context SFSB?
Regards
Peter -
10. Re: EJB3 Facade Design
echon May 24, 2006 10:45 AM (in response to echon)ok.. silly question.. they are not married to eachother if get by JNDI
-
-
12. Re: EJB3 Facade Design
echon May 25, 2006 2:14 PM (in response to echon)ok.. i've tested a lot yesterday and found out, that injected EJBs only share Lifecycle, but not the Transaction.
If i have 3 SFSB where the first inject the 2 other and make changes to DB via these 2 injected the db transaction is not used for both injected.
If the first injected Bean synchronizes successfully with DB and the second not the entries created in the first are not rolledback.
So is this a bug or is this the normal behaviour?
Regards
Peter -