-
1. Re: Injection of entityManger : @In or @PersistenceContext
keithnaas Feb 17, 2008 8:09 PM (in response to phread.fbricon.gmail.com)Are you using EJB3/JPA? If so, I don't know if it makes a difference. For non EJB3 POJOs, I think you need to use @In.
-
2. Re: Injection of entityManger : @In or @PersistenceContext
phread.fbricon.gmail.com Feb 17, 2008 8:28 PM (in response to phread.fbricon.gmail.com)Yes, I'm using EJB3 entities.
-
3. Re: Injection of entityManger : @In or @PersistenceContext
amitev Feb 17, 2008 8:56 PM (in response to phread.fbricon.gmail.com)Use @In for Seam managed persistence context (SMPC)
use @PersistenceContext for container managed persistence context.Component.getInstance("entityManager") = @In.
I strongly recommend using of SMPC.
-
4. Re: Injection of entityManger : @In or @PersistenceContext
keithnaas Feb 17, 2008 9:06 PM (in response to phread.fbricon.gmail.com)I second Adrian's comment about SMPC, unless of course you want to waste a lot of time debugging what is going on with @PersistenceContext :)
-
5. Re: Injection of entityManger : @In or @PersistenceContext
phread.fbricon.gmail.com Feb 17, 2008 9:40 PM (in response to phread.fbricon.gmail.com)Mmmh. From the DVDStore app, it seems Stateful EJBs use @PersistenceContext whereas Stateless EJBs use @In.
In some other examples (seamspace) Stateful EJBs use @In.Can you elaborate on the pros/cons of SMPC vs CMPC? (Sorry I'm a noob on the matter)
Thanks.
Fred B.
-
6. Re: Injection of entityManger : @In or @PersistenceContext
msystems Feb 17, 2008 9:59 PM (in response to phread.fbricon.gmail.com)http://docs.jboss.com/seam/2.0.1.GA/reference/en/html/persistence.html
A SMPC is propagated between components. A PersistenceContext (CMPC) is not propagated between components.
I.e. entities are always managed (not detached) between components, if you use a SMPC.
-
7. Re: Injection of entityManger : @In or @PersistenceContext
hucheng.chris.mandarinstudent.googlemail.com May 17, 2009 9:18 PM (in response to phread.fbricon.gmail.com)I am a newcomer to Seam but I understand that entities may not be managed in SMPC in the session scope. Is this true or did I misunderstand?
-
8. Re: Injection of entityManger : @In or @PersistenceContext
gonorrhea May 18, 2009 6:32 AM (in response to phread.fbricon.gmail.com)This is most likely true.
The funny thing is that the Seam Hotel Booking example in distro 2.1.1.GA still uses @PersisenceContext to inject an extended PC that is component-scoped rather than @In (SMPC which is conversation-scoped). see HotelBookingAction SFSB. HotelSearchingAction SFSB uses transaction-scoped PC. I'm not sure why GKing implemented this use case without SMPC.
http://docs.jboss.com/seam/2.1.0.GA/api/org/jboss/seam/persistence/ManagedPersistenceContext.html
A Seam component that manages a conversation-scoped extended persistence context that can be shared by arbitrary other components.
Always use @In in Seam to inject SMPC/EntityManager if you can, there are many benefits (one being a pre-requisite to use with Hibernate manual flush for atomic conversations).
-
9. Re: Injection of entityManger : @In or @PersistenceContext
gonorrhea May 18, 2009 6:39 AM (in response to phread.fbricon.gmail.com)org.jboss.seam.persistence.ManagedPersistenceContext.java:
@Scope(ScopeType.CONVERSATION) @BypassInterceptors @Install(false) public class ManagedPersistenceContext implements Serializable, HttpSessionActivationListener, Mutable, PersistenceContextManager, Synchronization {...}
If you for some reason need this component to be something other than CONVERSATION-scoped, you may have to extend and/or refactor this class and change the ScopeType in @Scope.
Most likely this is not recommended by the Seam devs. It makes sense to have one SMPC per LRC, not one SMPC for all LRCs in current session.
-
10. Re: Injection of entityManger : @In or @PersistenceContext
hucheng.chris.mandarinstudent.googlemail.com May 18, 2009 5:38 PM (in response to phread.fbricon.gmail.com)Thanks for the help guys, that clears things up regarding the session scope vs conversation. The source code snippet makes it pretty clear about the scope, I guess I should start looking in there next time.
-
11. Re: Injection of entityManger : @In or @PersistenceContext
israel.bgf May 18, 2009 6:13 PM (in response to phread.fbricon.gmail.com)So about transactions/persistence management plain Seam IS better than what EJB offers... At least it's what I see.