[jbossseam-issues] [JBoss JIRA] Commented: (JBSEAM-3028) add ContainerManagedPersistenceContext

Dan Allen (JIRA) jira-events at lists.jboss.org
Tue May 27 12:22:49 EDT 2008


    [ http://jira.jboss.com/jira/browse/JBSEAM-3028?page=comments#action_12414364 ] 
            
Dan Allen commented on JBSEAM-3028:
-----------------------------------

Quite simple, actually. A compliant Java EE 5 server (of which JBoss AS 4.2 is not) will automatically load persistence units defined in persistence.xml. Given that they are already loaded, it makes sense to use them from Seam (rather than having Seam load the persistence unit again). One way to do this is to define the persistence-unit-jndi-name in <persistence:managed-persistence-context>. However, that requires that you hook the persistence unit up to JNDI using a <resource-ref> in web.xml (again, compliant Java EE 5).

By using this component, you can avoid the JNDI step. It gets the container to inject an EntityManager into the @PersistenceContext field of this EJB component and then borrows that reference to be used in a Seam component. The benefit is that both the JavaBean component and another EJB can share the same persistence context (I think). At the very least, it simplifies configuration if you are deploying to a Java EE 5 server.

Configuration and usage:

<persistence:container-managed-persistence-context name="entityManager" auto-create="true"/>

@In private EntityManager entityManager;

> add ContainerManagedPersistenceContext
> --------------------------------------
>
>                 Key: JBSEAM-3028
>                 URL: http://jira.jboss.com/jira/browse/JBSEAM-3028
>             Project: Seam
>          Issue Type: Feature Request
>          Components: Core
>    Affects Versions: 2.1.0.A1, 2.0.2.GA
>            Reporter: Dan Allen
>         Assigned To: Dan Allen
>            Priority: Minor
>             Fix For: 2.1.0.GA
>
>         Attachments: JBSEAM-3028-v1.txt
>
>   Original Estimate: 2 hours
>  Remaining Estimate: 2 hours
>
> Perhaps this is silly, perhaps not. I have developed a wrapper around a container-managed persistence manager, avoiding the need to have to lookup the EntityManagerFactory in JNDI. The main limitation here is that you cannot use this with EJB components, so it is really just a convenience of configuration if the Java EE application server happens to offer the ability to create an EntityManager for you. This also only works with the default persistence unit.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://jira.jboss.com/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        



More information about the seam-issues mailing list