-
1. Re: ManagedPersistenceContext in Manning JPA book
amitev Nov 9, 2007 3:08 AM (in response to asookazian)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.
-
2. Re: ManagedPersistenceContext in Manning JPA book
delphi'sghost Nov 9, 2007 10:39 AM (in response to asookazian)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;
-
3. Re: ManagedPersistenceContext in Manning JPA book
amitev Nov 9, 2007 1:21 PM (in response to asookazian)Very detailed post. Thank you!
-
4. Re: ManagedPersistenceContext in Manning JPA book
segev Dec 3, 2007 5:53 PM (in response to asookazian)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? -
5. Re: ManagedPersistenceContext in Manning JPA book
pmuir Dec 3, 2007 6:02 PM (in response to asookazian)No, you shouldn't change the scope of an SMPC. Use an extended PC or http://wiki.jboss.org/wiki/Wiki.jsp?page=SeamEntityHomeForLongRunningContexts