Announcement Announcement Module
Collapse
No announcement yet.
Deploying a Roo JPA 2 App to GlassFish 3 Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Deploying a Roo JPA 2 App to GlassFish 3

    Deploying a Roo JPA 2 App to GlassFish 3


    Some configurations changes for a Roo WebApp to run it under GlassFish 3.x, in order to use container transactions

    JTA Steup

    * Perform jpa setup (or persistence) setup according to your environment, passing the parameters "--transactionManager JPA" and "--jndiDataSource jdbc/DS"

    Exemple

    Code:
    persistence setup --provider ECLIPSELINK --database MYSQL --jndiDataSource jdbc/DS --transactionManager JPA
    We could also set this manually without executing roo jpa setup command, see next

    Edit src/main/resources/META-INF/persistence.xml

    Certify that
    • Persistence-unit's "transaction-type" is set to JTA
    • An alement "jta-data-source" exists specifying the JNDI Name of the DataSource
    Example
    Code:
    ...
    <persistence-unit name="persistenceUnit" transaction-type="JTA">
            <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
            <jta-data-source>jdbc/DS</jta-data-source>
            <properties>
                ...
            </properties>
        </persistence-unit>
    </persistence>

    Edit file src/main/webapp/WEB-INF/web.xml


    * Add the following to the webapp deployment descriptor

    Code:
        <persistence-unit-ref>
           <persistence-unit-ref-name>persistence/defaultFactory</persistence-unit-ref-name>
           <persistence-unit-name>persistenceUnit</persistence-unit-name>
        </persistence-unit-ref>
    Note: Value for persistence-unit-name must match persistence unit name, the value for persistence-unit-ref-name will be used to perform a lookup for the EntiManager

    Edit file src/main/resources/META-INF/spring/applicationContext.xml


    * Remove bean definition for "org.springframework.orm.jpa.JpaTransactionManager "
    * Remove bean definition for "org.springframework.orm.jpa.LocalContainerEntityM anagerFactoryBean"
    * Remove entry with <jee:jndi-lookup id="dataSource" jndi-name="jdbc/DS"/>
    * Add the following entries
    Code:
        <tx:jta-transaction-manager userTransactionName="java:comp/UserTransaction" />
        <tx:annotation-driven mode="aspectj" transaction-manager="transactionManager"/>
        <jee:jndi-lookup id="entityManagerFactory" jndi-name="persistence/defaultFactory" expected-type="javax.persistence.EntityManagerFactory"/>
    Note the jndi-name in section <jee:jndi-lookup id="entityManagerFactory" ... /> should match the one defined in the webapp deployment descriptor in section persistence-unit-ref

    Dependencies changes

    As we will execute the WebAplication under GlassFish, we can remove some library dependencies that are already provided by the containner: One example jta
    We can also remove all pooling libraries added by Roo, and the JDBC Driver.

    The application will use a DataSource defined on the Java EE Container, there is no need to bundle this drivers with the application.
Working...
X