Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Note

This document applied to JBoss Seam 2.0.0.GA. Download it from http://sourceforge.net/project/showfiles.php?group_id=22866&package_id=163777&release_id=551158.

Note

This document now applies to the Geronimo 2.1 daily build (aka 2.1-SNAPSHOT). Until it's released you can download it from http://people.apache.org/~prasad/binaries/trunk/20071130/Image Removed. release.
Also, it is in the process of being updated - the instructions may only be partially corrected.
At this point the instruction have been updated up until the point before the new Hibernate transaction manager jar is installed in the Geronimo repository.
The remaining instructions should work, but they have not been tested yet.

Hibernate Transaction Manager Lookup class for Geronimo

...

To simplify the step here's how the tx manager lookup class is developed using Apache Maven 2. Noone No one said it's going to be easy, but just slightly easier than it needs to it's not as hard as it could be.

Go to any directory you want where the maven project for Hibernate Transaction Manager Lookup class for Geronimo is to be created.

No Format
bgColor#000000
borderStylesolid
jlaskowski@dev /cygdrive/c
$ bash-3.2$ mvn archetype:create -DgroupId=org.apache.geronimo.hibernate -DartifactId=geronimo-hibernate-transaction-manager-lookup
[INFO] Scanning for projects...
[INFO] Searching repository for plugin with prefix: 'archetype'.
[INFO] ----------------------------------------------------------------------------
[INFO] Building Maven Default Project
[INFO]    task-segment: [archetype:create] (aggregator-style)
[INFO] ------------------------------------------------------------------------
...
[INFO] -----
[INFO] Preparing archetype:create
[INFO] No goals needed for project - skipping
Downloading: http://repo1.maven.org/maven2/org/apache/geronimo/hibernate/wagon-http-shared/1.0-beta-2/wagon-http-shared-1.0-beta-2.pom
Downloading: http://repo1.maven.org/maven2/org/apache/geronimo/hibernate/wagon-http-shared/1.0-beta-2/wagon-http-shared-1.0-beta-2.pom
[INFO] Setting property: classpath.resource.loader.class => 'org.codehaus.plexus.velocity.ContextClassLoaderResourceLoader'.
[INFO] Setting property: velocimacro.messages.on => 'false'.
[INFO] Setting property: resource.loader => 'classpath'.
[INFO] Setting property: resource.manager.logwhenfound => 'false'.
[INFO] [archetype:create]
Choose archetype:
1: internal -> appfuse-basic-jsf (AppFuse archetype for creating a web application with Hibernate, Spring and JSF)
2: internal -> appfuse-basic-spring (AppFuse archetype for creating a web application with Hibernate, Spring and Spring MVC)
3: internal -> appfuse-basic-struts (AppFuse archetype for creating a web application with Hibernate, Spring and Struts 2)
4: internal -> appfuse-basic-tapestry (AppFuse archetype for creating a web application with Hibernate, Spring and Tapestry 4)
5: internal -> appfuse-core (AppFuse archetype for creating a jar application with Hibernate and Spring and XFire)
6: internal -> appfuse-modular-jsf (AppFuse archetype for creating a modular application with Hibernate, Spring and JSF)
7: internal -> appfuse-modular-spring (AppFuse archetype for creating a modular application with Hibernate, Spring and Spring MVC)
8: internal -> appfuse-modular-struts (AppFuse archetype for creating a modular application with Hibernate, Spring and Struts 2)
9: internal -> appfuse-modular-tapestry (AppFuse archetype for creating a modular application with Hibernate, Spring and Tapestry 4)
10: internal -> maven-archetype-j2ee-simple (A simple J2EE Java application)
11: internal -> maven-archetype-marmalade-mojo (A Maven plugin development project using marmalade)
12: internal -> maven-archetype-mojo (A Maven Java plugin development project)
13: internal -> maven-archetype-portlet (A simple portlet application)
14: internal -> maven-archetype-profiles ()
15: internal -> maven-archetype-quickstart ()
16: internal -> maven-archetype-site-simple (A simple site generation project)
17: internal -> maven-archetype-site (A more complex site project)
18: internal -> maven-archetype-webapp (A simple Java web application)
19: internal -> struts2-archetype-starter (A starter Struts 2 application with Sitemesh, DWR, and Spring)
20: internal -> struts2-archetype-blank (A minimal Struts 2 application)
21: internal -> struts2-archetype-portlet (A minimal Struts 2 application that can be deployed as a portlet)
22: internal -> struts2-archetype-dbportlet (A starter Struts 2 portlet that demonstrates a simple CRUD interface with db backing)
23: internal -> struts2-archetype-plugin (A Struts 2 plugin)
24: internal -> shale-archetype-blank (A blank Shale web application with JSF)
25: internal -> maven-adf-archetype (Archetype to ease the burden of creating a new application based with ADF)
26: internal -> data-app (A new Databinder application with sources and resources.)
27: internal -> jini-service-archetype (Archetype for Jini service project creation)
28: internal -> softeu-archetype-seam (JSF+Facelets+Seam Archetype)
29: internal -> softeu-archetype-seam-simple (JSF+Facelets+Seam (no persistence) Archetype)
30: internal -> softeu-archetype-jsf (JSF+Facelets Archetype)
31: internal -> jpa-maven-archetype (JPA application)
32: internal -> spring-osgi-bundle-archetype (Spring-OSGi archetype)
33: internal -> confluence-plugin-archetype (Atlassian Confluence plugin archetype)
34: internal -> maven-archetype-har (Hibernate Archive)
35: internal -> maven-archetype-sar (JBoss Service Archive)
36: internal -> wicket-archetype-quickstart (A simple Apache Wicket project)
Choose a number:  (1/2/3/4/5/6/7/8/9/10/11/12/13/14/15/16/17/18/19/20/21/22/23/24/25/26/27/28/29/30/31/32/33/34/35/36): 15
[INFO] artifact org.apache.maven.archetypes:maven-archetype-quickstart: checking for updates from maven-archetype-quickstart-repo
Define value for version: : 1.0-SNAPSHOT
Define value for package: : org.apache.geronimo.hibernate
Confirm properties configuration:
groupId: org.apache.geronimo.hibernate
artifactId: geronimo-hibernate-transaction-manager-lookup
version: 1.0-SNAPSHOT
package: org.apache.geronimo.hibernate
 Y: :
[INFO] ----------------------------------------------------------------------------
[INFO] Using following parameters for creating ArchetypeOldArchetype: maven-archetype-quickstart:RELEASE
[INFO] ----------------------------------------------------------------------------
[INFO] Parameter: groupId, Value: org.apache.geronimo.hibernate
[INFO] Parameter: packageName, Value: org.apache.geronimo.hibernate
[INFO] Parameter: basedir, Value: c:\/home/jaydm
[INFO] Parameter: package, Value: org.apache.geronimo.hibernate
[INFO] Parameter: version, Value: 1.0-SNAPSHOT
[INFO] Parameter: artifactId, Value: geronimo-hibernate-transaction-manager-lookup
[INFO] ********************* End of debug info from resources from generated POM ***********************
[INFO] ArchetypeOldArchetype created in dir: c:\/home/jaydm/geronimo-hibernate-transaction-manager-lookup
[INFO] --------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 47 seconds
[INFO] Finished at: Thu Feb 21 19:21:55 CST 2008
[INFO] Final BUILD SUCCESSFULMemory: 8M/40M
[INFO] ------------------------------------------------------------------------

Notice that there are a couple of inputs that you must make:
1) When Maven asks you to select an archetype type - choose quickstart, enter: 15
2) When Maven asks you for a value of the version, enter: 1.0-SNAPSHOT
3) When Maven asks you for the package, enter: org.apache.geronimo.hibernate

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.xml
<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.4.sp1</version>
            <exclusions>
                <exclusion>
                    <groupId>javax.transaction</groupId>
                    <artifactId>jta</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.apache.geronimo.modules<framework</groupId>
            <artifactId>geronimo-kernel</artifactId>
            <version>2.1-SNAPSHOT<1</version>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.5</source>
source>
                    <target>1.5</target>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

Change your working directory to the project's directory, e.g. c:/geronimo-hibernate-transaction-manager-lookup and do the following steps from within it.

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

Delete src/main/java/org/apache/geronimo/hibernate/App.java.

Delete src/test/java/org/apache/geronimo/hibernate/AppTest.java.

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.GeronimoTransactionManagerLookup
package org.apache.geronimo.hibernate.transaction;

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

import javax.managementtransaction.ObjectNameTransactionManager;

import javax.transaction.TransactionManagerorg.apache.geronimo.gbean.AbstractName;
import org.apache.geronimo.hibernategbean.HibernateExceptionAbstractNameQuery;
import org.hibernateapache.geronimo.transactionkernel.TransactionManagerLookupKernel;
import org.apache.geronimo.kernel.*KernelRegistry;
import org.apache.geronimo.gbean.*.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);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;
    }
}

Build GeronimoTransactionManagerLookup class with mvn -Dmaven.test.skip=true install command.

No Format
bgColor#000000
borderStylesolid
$ mvn -Dmaven.test.skip=true install
[INFO] Scanning for projects...
[INFO] ----------------------------------------------------------------------------
[INFO] Building geronimo-hibernate-transaction-manager-lookup
[INFO]    task-segment: [install]
[INFO] ----------------------------------------------------------------------------
[INFO] [resources:resources]
[INFO] Using default encoding to copy filtered resources.
[INFO] [compiler:compile]
[INFO] Compiling 21 source filesfile to c:\/home/jaydm/geronimo-hibernate-transaction-manager-lookup\/target\/classes
[INFO] [resources:testResources]
[INFO] Using default encoding to copy filtered resources.
[INFO] [compiler:testCompile]
[INFO] Not compiling test sourcesNothing to compile - all classes are up to date
[INFO] [surefire:test]
[INFO] No Teststests areto skippedrun.
[INFO] [jar:jar]
[INFO] Building jar: c:\/home/jaydm/geronimo-hibernate-transaction-manager-lookup\/target\/geronimo-hibernate-transaction-manager-lookup-1.0-SNAPSHOT.jar
[INFO] [install:install]
[INFO] Installing c:\/home/jaydm/geronimo-hibernate-transaction-manager-lookup\/target\/geronimo-hibernate-transaction-manager-lookup-1.0-SNAPSHOT.jar to 
C:\/home/jaydm/.m2\/repository/org\/apache\/geronimo\/hibernate\/transaction\/geronimo-hibernate-transaction-manager-lookup\/1.0-SNAPSHOT\/geronimo-hibernate-transaction-manager-lookup-1.0-SNAPSHOT.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2 seconds
[INFO] Finished at: Thu Feb 21 19:55:10 CST 2008
[INFO] Final Memory: 10M/54M
[INFO] ------------------------------------------------------------------------

Note that the file is installed into your maven local repository, e.g. C:\.m2\org\apache\geronimo\hibernate\transaction\geronimo-hibernate-transaction-manager-lookup\1.0-SNAPSHOT\geronimo-hibernate-transaction-manager-lookup-1.0-SNAPSHOT.jar.

Install the file to Geronimo artifact repository, i.e. ${GERONIMO_HOME}/repository.

...