[jbossseam-issues] [JBoss JIRA] Commented: (JBSEAM-2785) Redesign PersistenceProvider to provide runtime detectetion of JPA impl in use

Eric Jung (JIRA) jira-events at lists.jboss.org
Fri Mar 28 13:58:48 EDT 2008


    [ http://jira.jboss.com/jira/browse/JBSEAM-2785?page=comments#action_12405531 ] 
            
Eric Jung commented on JBSEAM-2785:
-----------------------------------

There's a solution for this which leverages JNDI and wouldn't require a new tag. I don't know if this is best written in this bug or in 1946, so forgive me if I've chosen the wrong one.

I'm going to show the steps for Websphere Application Server with org.hibernate.ejb.HibernatePersistence as the persistence provider, but the steps are transferable to any persistence provider (including openJPA). Whether or not it's transferable to other app servers depends on whether those app servers support object loading via object factories (http://java.sun.com/j2se/1.4.2/docs/api/javax/naming/spi/ObjectFactory.html). Since ObjectFactory is part of the JNDI specification, I imagine any J2EE-compliant app server should support it.

Steps in Websphere Application Server 6.1 (also works in 5.x). See attached screenshots, too. In the administrative console:

1. Define a Resource Environment Provider
    a. Goto Resources->Resource Environment->Resource Environment Providers. Press "New"
    b. Enter a name. I chose "JPA" but "Seam Bridge" might have been more appropriate. Click "Apply" then "Save".
  2. Define a Referenceable
    a. From the Resource Environment Provider list, click the Resource Environment Provider you created in step one.
    b. Under "Additional Properties", click "Referenceables"
    ***c. Click "New" and enter com.company.EMFactoryBridge for "Factory Class Name" and javax.persistence.EntityManagerFactory for "Class Name"
    d. Click "Apply" then "Save"
3. Define a Resource Environment Entry
    a. Goto Resources->Resource Environment->Resource environment entries. Press "New".
    b. Ensure the Resource Environment Provider you created in step 1 is selected in the "Provider" drop-down list.
    c. Enter EMFactoryBridge (or whatever you like) for "Name". Enter seam/EMFactoryBridge for JNDI name. This is the value Seam will use to instantiate your provider, expecting it to return a javax.persistence.EntityManagerFactory instance.
    d. Ensure com.company.EMFactoryBridge is selected in the "Referenceables" drop-down list.
    e. Click Apply then Save.
4. Provide the persistence unit name to the EMFactoryBridge
    a. Goto Resources->Resource Environment->Resource environment entries and click the entry created in step 3 (EMFactoryBridge)
    b. Under Additional Properties, click "Custom properties"
    c. Click New
    d. Under "Name", enter persistence-unit-name
    e. Under "Value", enter the name of the persistence unit in persistence.xml to be used by this EntityManager. This is the attribute "name" on the <persistence-unit/> element. See attached sample. Here I've chosen "bookingDatabase" as the name.
    d. Ensure java.lang.String is selected in the "Type" drop-down list.
    e. Click Apply then Save.
5. In components.xml, specify seam/EMFactoryBridge (or whatever value is chose in step 3c) for the persistence-unit-jndi-name attribute of the <persistence:managed-persistence-context/> element. See attached example.
6. Ensure the attached class is in your application's CLASSPATH at runtime (not necessary at build time)

You can now use any persistence provider you like, specified in persistence.xml as usual. You can now inject EntityManager instances into non-EJBs using @In (without @PersistenceContext).

*** Hopefully, you'll integrate the attached org.jboss.seam.persistence.EMFactoryBridge patch into the trunk. Then the user can specify org.jboss.seam.persistence.EMFactoryBridge here and not have to include the attached class in each and every Seam project. Step 6 would also be obsolete.


> Redesign PersistenceProvider to provide runtime detectetion of JPA impl in use
> ------------------------------------------------------------------------------
>
>                 Key: JBSEAM-2785
>                 URL: http://jira.jboss.com/jira/browse/JBSEAM-2785
>             Project: JBoss Seam
>          Issue Type: Feature Request
>          Components: Core
>    Affects Versions: 2.1.0.A1, 2.0.1.GA
>            Reporter: Pete Muir
>         Assigned To: Pete Muir
>            Priority: Blocker
>             Fix For: 2.1.0.BETA1
>
>         Attachments: EMFactoryBridge.java, step1a.png, step1b.png, step2a-1.png, step2a-2.png, step2b.png, step2c.png, step3.png, step4.png
>
>


-- 
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