It's not necessary, but it's strongly recommended to use seam managed persistence context. With SMPC you can use features like s:convertEntity, EntityQuery, EntityHome ...etc.
My understanding of it is that :
@PersistenceContext (EJB PC) - Single shot persistence context for the duration of the method call
@PersistenceContext(Type=EXTENDED) (Extended EJB PC) - Persistence context that lasts for the duration of the session bean, but not shareable across session beans.
@In private EntityManager entityManager (SMPC) - Seam Managed Persistence Context that is tied to the conversation and can be used in multiple method calls, and across multiple beans. As amitev mentions, you get a lot of extras for free with the SMPC.
The SMPC also gets rid of lazy initialization errors by using two transactions on a request. One to commit the work, and then another to let you read database entities when rendering the view if you use the Seam transactional phase listener.
If you are working in a Seam-Gen generated app, you should be ready to start using SMPCs already without requiring any tweaking with the config.
You use SMPCs in your beans by injecting the entityManager using the following :
@In private EntityManager entityManager;
Very detailed post. Thank you!
We decided to use SMPC for all the reasons highlighted in the previous post but there is a catch if you use it in a Session scoped stateful session bean. the injected entity manager will have a scope of Conversation (by default) and transactions will not be committed properly. This can be demonstrated by changing the Seam supplied messages example to use SMCP instead of the original EJB extended PC.
Is it OK to change the default scope of the SMPC component to session scope?
Can the above SMPC be used for conversations?