Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

...

Replace the content of pom.xml which is the main configuration file of any maven project to the following:

Code Block
XML
XML
borderStylesolid
titlepom.xmlXML
<project xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>org.apache.geronimo.hibernate.transaction</groupId>
    <artifactId>geronimo-hibernate-transaction-manager-lookup</artifactId>
    <packaging>jar</packaging>
    <version>1.0-SNAPSHOT</version>
    <name>geronimo-hibernate-transaction-manager-lookup</name>
    <url>http://maven.apache.org</url>
    <dependencies>
        <dependency>
            <groupId>org.apache.geronimo.specs</groupId>
            <artifactId>geronimo-jta_1.1_spec</artifactId>
            <version>1.1</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate</artifactId>
            <version>3.2.5.ga</version>
            <exclusions>
                <exclusion>
                    <groupId>javax.transaction</groupId>
                    <artifactId>jta</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.apache.geronimo.framework</groupId>
            <artifactId>geronimo-kernel</artifactId>
            <version>2.1.1</version>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.5</source>
                    <target>1.5</target>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

...

Create the org.apache.geronimo.hibernate.transaction.GeronimoTransactionManagerLookup class in src/main/java/org/apache/geronimo/hibernate/transaction/ directory.

Code Block
JAVA
JAVA
borderStylesolid
titleorg.apache.geronimo.hibernate.transaction.GeronimoTransactionManagerLookupJAVA
package org.apache.geronimo.hibernate.transaction;

import java.util.Properties;
import java.util.Set;

import javax.transaction.TransactionManager;

import org.apache.geronimo.gbean.AbstractName;
import org.apache.geronimo.gbean.AbstractNameQuery;
import org.apache.geronimo.kernel.Kernel;
import org.apache.geronimo.kernel.KernelRegistry;
import org.hibernate.HibernateException;
import org.hibernate.transaction.TransactionManagerLookup;

public class GeronimoTransactionManagerLookup implements TransactionManagerLookup {

    public static final String UserTransactionName = "java:comp/UserTransaction";

    public TransactionManager getTransactionManager(Properties props) throws HibernateException {
        try {
            Kernel kernel = KernelRegistry.getSingleKernel();
            AbstractNameQuery query = new AbstractNameQuery(TransactionManager.class.getName ());
            Set<AbstractName> names = kernel.listGBeans(query);
            
            if (names.size() != 1) {
                throw new IllegalStateException("Expected one transaction manager, not " + names.size());
            }
            
            AbstractName name = names.iterator().next();
            TransactionManager transMg = (TransactionManager)
            kernel.getGBean(name);
            
            return (TransactionManager)transMg;
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println();
            
            throw new HibernateException("Geronimo Transaction Manager Lookup Failed", e);
        }
    }

    public String getUserTransactionName() {
        return UserTransactionName;
    }
}

...

Without delving into much detail it boils down to patching org.hibernate.ejb.Ejb3Configuration to avoid NPE. Download the class from its source code repository at http://fisheye.jboss.com/browse/Hibernate/entitymanager/trunk/src/java/org/hibernate/ejb/Ejb3Configuration.java and patch it with the following changes:

Code Block
JAVA
JAVA
borderStylesolid
titleEjb3Configuration.patchJAVA
--- src/org/hibernate/ejb/Ejb3Configuration.java        2007-11-30 13:36:31.234375000 +0100
+++ src/org/hibernate/ejb/Ejb3Configuration.java.patched        2007-11-30 13:39:33.609375000 +0100
@@ -341,9 +341,11 @@

                        boolean[] detectArtifactForOtherJars = getDetectedArtifacts( info.getProperties(), null, false );
                        boolean[] detectArtifactForMainJar = getDetectedArtifacts( info.getProperties(), null, info.excludeUnlistedClasses() );
+                       if (info.getJarFileUrls() != null) {
                        for ( URL jar : info.getJarFileUrls() ) {
                                scanForClasses( jar, packages, entities, hbmFiles, detectArtifactForOtherJars, searchForORMFiles );
                        }
+                   }
                        scanForClasses( info.getPersistenceUnitRootUrl(), packages, entities, hbmFiles, detectArtifactForMainJar, searchForORMFiles );

                        Properties properties = info.getProperties() != null ?

...

The plan configures necessary Geronimo resources to deploy JBoss Seam's booking sample application.

Code Block
xml
xml
borderStylesolid
titlejboss-seam-jee5-geronimo-plan.xmlxml
<?xml version="1.0" encoding="UTF-8"?>
<application xmlns="http://geronimo.apache.org/xml/ns/j2ee/application-2.0">
  <environment xmlns="http://geronimo.apache.org/xml/ns/deployment-1.2">
    <moduleId>
      <groupId>org.jboss.seam.examples.jee5</groupId>
      <artifactId>jboss-seam-jee5</artifactId>
      <version>2.0.0.GA</version>
      <type>ear</type>
    </moduleId>
    <dependencies>
      <dependency>
        <groupId>org.apache.geronimo.hibernate.transaction</groupId>
        <artifactId>geronimo-hibernate-transaction-manager-lookup</artifactId>
        <type>jar</type>
      </dependency>
    </dependencies>
  </environment>
  <module>
    <web>jboss-seam-jee5.war</web>
    <web-app xmlns="http://geronimo.apache.org/xml/ns/j2ee/web-2.0.1">
      <environment xmlns="http://geronimo.apache.org/xml/ns/deployment-1.2">
        <moduleId>
          <groupId>org.jboss.seam.examples.jee5</groupId>
          <artifactId>jboss-seam-jee5</artifactId>
          <version>2.0.0.GA</version>
          <type>war</type>
        </moduleId>
      </environment>
      <context-root>/seam-jee5</context-root>
    </web-app>
  </module>
  <module>
    <ejb>jboss-seam-jee5.jar</ejb>
    <openejb-jar xmlns="http://www.openejb.org/xml/ns/openejb-jar-2.1">
      <environment xmlns="http://geronimo.apache.org/xml/ns/deployment-1.2">
        <moduleId>
          <groupId>org.jboss.seam.examples.jee5</groupId>
          <artifactId>jboss-seam-jee5</artifactId>
          <version>2.0.0.GA</version>
          <type>jar</type>
        </moduleId>
      </environment>
      <!-- overrides what's in the module's persistence.xml -->
      <persistence xmlns="http://java.sun.com/xml/ns/persistence">
        <persistence-unit name="bookingDatabase">
          <jta-data-source>jdbc/__default</jta-data-source>
          <class>org.jboss.seam.example.booking.Booking</class>
          <class>org.jboss.seam.example.booking.Hotel</class>
          <class>org.jboss.seam.example.booking.User</class>
          <exclude-unlisted-classes>true</exclude-unlisted-classes>
          <properties>
            <property name="hibernate.transaction.manager_lookup_class"
              value="org.apache.geronimo.hibernate.transaction.GeronimoTransactionManagerLookup" />
          </properties>
        </persistence-unit>
        <!-- change the way the default PU works - make it an alias to bookingDatabase PU -->
        <persistence-unit name="cmp">
          <class>org.jboss.seam.example.booking.Booking</class>
          <class>org.jboss.seam.example.booking.Hotel</class>
          <class>org.jboss.seam.example.booking.User</class>
          <exclude-unlisted-classes>true</exclude-unlisted-classes>
        </persistence-unit>
      </persistence>
    </openejb-jar>
  </module>
  <ext-module>
    <connector>seam-jee5-dbpool</connector>
    <external-path xmlns:dep="http://geronimo.apache.org/xml/ns/deployment-1.2">
      <dep:groupId>org.tranql</dep:groupId>
      <dep:artifactId>tranql-connector-derby-embed-xa</dep:artifactId>
      <dep:type>rar</dep:type>
    </external-path>
    <connector xmlns="http://geronimo.apache.org/xml/ns/j2ee/connector-1.2">
      <environment xmlns="http://geronimo.apache.org/xml/ns/deployment-1.2">
        <moduleId>
          <groupId>org.jboss.seam.examples.jee5</groupId>
          <artifactId>booking-dbpool</artifactId>
          <version>2.0.0.GA</version>
          <type>rar</type>
        </moduleId>
        <dependencies>
          <dependency>
            <groupId>org.apache.geronimo.configs</groupId>
            <artifactId>system-database</artifactId>
            <type>car</type>
          </dependency>
        </dependencies>
      </environment>
      <resourceadapter>
        <outbound-resourceadapter>
          <connection-definition>
            <connectionfactory-interface>javax.sql.DataSource</connectionfactory-interface>
            <connectiondefinition-instance>
              <name>jdbc/__default</name>
              <config-property-setting name="DatabaseName">SystemDatabase</config-property-setting>
              <connectionmanager>
                <local-transaction />
                <single-pool>
                  <max-size>100</max-size>
                  <blocking-timeout-milliseconds>5000</blocking-timeout-milliseconds>
                  <select-one-assume-match />
                </single-pool>
              </connectionmanager>
            </connectiondefinition-instance>
          </connection-definition>
        </outbound-resourceadapter>
      </resourceadapter>
    </connector>
  </ext-module>
</application>

...