You are not going to have any issue using Seam managed persistence context instead of the standard container managed persistence context, so in my opinion the best practice is using @In
.
Among the advantages of using a Seam managed persistence context there are:
- You can inject the same persistence context in non-EJB Seam component
- Use of
<s:convertEntity>
in the view (assuming you are going to use JSF)
- Use of EL in the Query Language
- You have the persistence context bound to the conversation context (not important for you, if understand correct)
If you choose @In
, thus Seam managed persistence context, then you can have declarative transaction demarcation using @Transactional
in non-EJB Seam component where @TransactionAttribute
make no sense.
For EJB session bean annotated as Seam component (@Name
) @TransactionAttribute
should be used with the same semantic as defined for EJB3.
Since @Transactional
doesn't have a REQUIRES_NEW
value the following applies as explained in the reference documentation:
If you are using EJB3 and mark your class or method @TransactionAttribute(REQUIRES_NEW)
then the transaction and persistence context shouldn't be propagated to method calls on this
object. However as the Seam-managed persistence context is propagated to any component
within the conversation, it will be propagated to methods marked REQUIRES_NEW
. Therefore,
if you mark a method REQUIRES_NEW
then you should access the entity manager using
@PersistenceContext
.
Chapter 9 of Dan Allen book Seam In Action will satisfy any doubt on this topic.