So I was just reading the Bauer and King JPA with Hibernate book. pretty decent book BTW.
on pgs. 514-515, they discuss transaction- and persistence-context propagation rules and scenarios.
Write your DAOs as stateful EJBs if you write your controller as a stateful session bean. This issue is another
nasty side effect of the missing FlushModeType.MANUAL that can seriously impact how you design and layer
applications. We recommend you rely on the Hibernate extension until the EJB 3.0 specification is fixed.
With FlushMode.MANUAL, your controllers don't have to use TransactionAttributeType.NOT_SUPPORTED, and the
persistence context is always propagated along with your transaction (and you can mix stateless and stateful
EJB calls easily).
On pg. 509, one of the propagation rules is:
If a stateless component is invoked, and the caller doesn't have an active tx, or the tx isn't propagated into
the called component, a new persistence context is created when the EntityManager is called inside the stateless
component. In other words, no propagation of a persistence context occurs if no transaction is propagated.
The controller above refers to conversation controller which is a SFSB.
I'm trying to understand if you absolutely must use SFSB DAO's or not. What are the repercussions of calling a DAO method from a SFSB in the following two scenarios:
1) TransactionAttributeType.NOT_SUPPORTED (controller method)
2) TransactionAttributeType.REQUIRED (controller method)
What if the DAOs are POJOs (i.e., non-EJBs)?
This section of the book is outside of a Seam context. How do the rules apply in a Seam app? Any difference in rules?
Seems to me as long as there's an active transaction and the transaction gets propagated from controller method to DAO method, then the persistence context will be propagated as well. So if you use a SFSB controller method with REQUIRED transaction type that calls a SLSB or SFSB DAO method with REQUIRED or SUPPORTS or MANDATORY, you should be good.
So why must the DAO be SFSB??