Showing posts with label javaee. Show all posts
Showing posts with label javaee. Show all posts

Saturday, September 5, 2009

Deploying to Geronimo from your Netbeans Project

I used to be a major Eclipse fan. I thought Netbeans was useless and featureless. It certain has less Java editing features compared to Eclipse, which has brilliant ones like the Java Search and it's refactoring functions, but it's got a much better design and is more rounded off. So it's not as messy and over done as Eclipse tends to be. Take for an example Eclipse's RCP framework. If you've ever done RCP programming in Eclipse you would have noticed that they went too far in making things declarative and this leads to inconsistencies sometimes, like when you want to add menu items. In some cases you have can do it declarative but in certain cases you need to do it with code, and in even other cases you need to mix the 2.

I prefer to keep things consistent. This allows you to document things more clearly and for new programmers (and even yourself in a few months) to not waste too much time getting up to speed with every small things he runs into. The Netbeans RCP is brilliant. It's got a clean design and layout, and integrates well into the IDE's other features like the JavaEE Application Client and GUI builder. Further Netbeans specialized plugins are maybe not an attempt at long features lists, but they're stable and do their purpose well. They offer everything you need to complete your task. Eclipse tends to have so many features, that none of them are production quality yet. And they tried to abstract things to such a degree, that certain features feel "loose" and not well integrated.

But the point is not to compare Netbeans and Eclipse.

Customizing the Netbeans Build Process
Eclipse has a Geronimo plugin, something which Netbeans does not have yet. There are some projects for Geronimo Netbeans plugins, but they're all dead. It does seem like the 6.8 Netbeans will have the ability to add a Geronimo server though. But until then you need to make other plans when trying to integrate the Geronimo deploy process into your Netbeans projects.

Netbeans has another great feature which makes this easier. In Netbeans your projects are built with ant. The IDE generates a file called "nbproject/build-impl.xml", and this is where all the build logic is found. Though in the root of your project you will find the standard "build.xml". It's this build.xml file which includes the generated build file. To allow for build customization, the generated build file has a couple of empty ant targets, which you can override in your build.xml. There are pre/post targets for all the different tasks performed by the user, such as clean, compile, package, etc. You can also override the main build targets, though you would have to implement them if you don't want to break them.

So, if you wanted to do obfuscate your class files, you can override the "-post-compile" target, and run the obfuscate task, like so:
        <target name="-post-compile">
          <obfuscate>
              <fileset dir="${build.classes.dir}">
              </fileset>
          </obfuscate>
        </target>
So, to integrate into the Geronimo deploy process, we will modify our build.xml. When you create your project, just create it with any "local" server. I use Glassfish 2 since it shipped with my Netbeans download. We will not be using Glassfish, since we're overriding the behaviour of the ant targets. When Netbeans deploys a project it executes the "run-deploy" task, so this is where we'll hook into. Also note that these instruction will only work on Linux (or other Unixes), since I have an "isdeployed.sh" script to make it easier to check if an application is deployed. I'll find a more portable way to do it at another time, and if you do it, please send along your changes. For the mean time though, I did add instructions to the end to get a more limited deployment for those users who aren't developing on *nix.

Deploying to Geronimo
First step is to create a file called "geronimo-ant-deploy.xml" next to your "build.xml", and give it the following contents:
<?xml version="1.0" encoding="UTF-8"?>
<project name="geronimo-ant-deploy" default="geronimo-init" basedir=".">
  <dirname property="basedir.geronimo-ant-deploy" file="${ant.file.geronimo-ant-deploy}"/>

  <property file="nbproject/project.properties"/>
  <property file="${basedir.geronimo-ant-deploy}/geronimo-ant-deploy.properties"/>

  <target name="geronimo-init">
    <property name="geronimo.deploy-name" value="${deploy.moduleId} (${deploy.module})"/>

    <condition property="geronimo.init.dependencies-satisfied">
      <and>
        <isset property="deploy.plan" />
        <isset property="deploy.module" />
        <isset property="deploy.moduleId" />
      </and>
    </condition>

    <condition property="geronimo.is-deployed">
      <and>
        <isset property="deploy.disable-deploy-check"/>
        <equals arg1="${deploy.disable-deploy-check}" arg2="deployed"/>
      </and>
    </condition>

    <fail unless="geronimo.init.dependencies-satisfied">
      Failed to deploy:
      1. You need to set the deploy.plan property to the path to the deploy plan .xml file 
         (Current Value: ${deploy.plan})
      2. You need to set the deploy.module property to the path to the module (archive) to deploy 
         (Current Value: ${deploy.module})
      3. You need to set the deploy.moduleId property to the Geronimo module ID for this project.
         You can find the required value for this in ${deploy.plan} (deploy.plan) as the <dep:moduleId> tag,
         and it would be in the form: groupId/artifactId/version/type
    </fail>
  </target>

  <target name="geronimo-check-deployed" depends="geronimo-init" unless="deploy.disable-deploy-check" 
      description="Checks if the app has been deployed">
    <echo>Checking if module ${geronimo.deploy-name} is already deployed</echo>
    <exec dir="${geronimo.home}" executable="${geronimo.bin}/${geronimo.isdeployed}" 
        resultproperty="geronimo.check-module">
      <arg line="${deploy.moduleId} --user ${geronimo.user} --password ${geronimo.pwd}"/>
    </exec>

    <condition property="geronimo.check-succeeded">
      <or>
        <equals arg1="${geronimo.check-module}" arg2="255"/>
        <equals arg1="${geronimo.check-module}" arg2="0"/>
      </or>
    </condition>

    <fail unless="geronimo.check-succeeded">
      Failed to check if module ${geronimo.deploy-name} is already deployed
    </fail>

    <condition property="geronimo.is-deployed">
      <equals arg1="${geronimo.check-module}" arg2="0"/>
    </condition>
  </target>

  <!-- UNDEPLOY -->
  <target name="geronimo-not-undeploy" depends="geronimo-check-deployed" unless="geronimo.is-deployed" 
      description="Handles the case of the application not being deployed when trying to undeploy">
    <echo>Module is not currently deployed. Not undeploying module ${geronimo.deploy-name}.</echo>
  </target>

  <target name="geronimo-do-undeploy" depends="geronimo-check-deployed" if="geronimo.is-deployed" 
      description="Undeploying webapp in geronimo action">
    <echo>Undeploying ${geronimo.deploy-name}</echo>

    <exec dir="${geronimo.home}" executable="${geronimo.bin}/${geronimo.deploy}" failonerror="true">
      <arg line="--user ${geronimo.user} --password ${geronimo.pwd} undeploy ${deploy.moduleId}"/>
    </exec>

    <echo>Undeployed ${geronimo.deploy-name}</echo>
  </target>

  <target name="geronimo-undeploy" 
      depends="geronimo-init,geronimo-check-deployed,geronimo-not-undeploy,geronimo-do-undeploy" 
      description="Undeploying webapp in geronimo entry point">
  </target>

  <!-- DEPLOY -->
  <target name="geronimo-newdeploy" depends="geronimo-check-deployed" unless="geronimo.is-deployed" 
      description="Deploying new webapp in geronimo action">
    <echo>Not deployed, deploying new application ${geronimo.deploy-name}</echo>

    <exec dir="${geronimo.home}" executable="${geronimo.bin}/${geronimo.deploy}" failonerror="true">
      <arg line="--user ${geronimo.user} --password ${geronimo.pwd} deploy ${basedir}/${deploy.module} ${basedir}/${deploy.plan}"/>
    </exec>

    <echo>Deployed ${geronimo.deploy-name}</echo>
  </target>

  <target name="geronimo-redeploy" depends="geronimo-check-deployed" if="geronimo.is-deployed" 
      description="Redeploying webapp in geronimo action">
    <echo>Already deployed, redeploying ${geronimo.deploy-name}</echo>

    <exec dir="${geronimo.home}" executable="${geronimo.bin}/${geronimo.deploy}" failonerror="true">
      <arg line="--user ${geronimo.user} --password ${geronimo.pwd} redeploy ${basedir}/${deploy.module} ${basedir}/${deploy.plan}"/>
    </exec>

    <echo>Deployed ${geronimo.deploy-name}</echo>
  </target>

  <target name="geronimo-deploy" 
      depends="geronimo-init,geronimo-check-deployed,geronimo-newdeploy,geronimo-redeploy" 
      description="Deploying webapp in geronimo entry point">
  </target>
</project>
Then, in the same directory, create a file called "geronimo-ant-deploy.properties", and give it the following contents (updating them to suite your installation):
kms.home=/opt
geronimo.home=${kms.home}/server/geronimo
geronimo.url=http://localhost:8080/
geronimo.bin=${geronimo.home}/bin
geronimo.lib=${geronimo.home}/lib
geronimo.user=system
geronimo.pwd=manager
geronimo.start=startup.sh
geronimo.stop=shutdown.sh
geronimo.deploy=deploy.sh
geronimo.isdeployed=isdeployed.sh
Lastly, in your Geronimo installation directory (the one listed in geronimo.home above), create a file called "isdeployed.sh" in the "bin" subdirectory, with the following contents:
#!/bin/bash

if [ "$2" = "" ]; then
  echo "Usage: $0 <moduleName> <deploy.sh arg1>..<deploy.sh argN>" >&2
  echo "After the module name you wish to check, you need to supply any other options you wish to " >&2
  echo "Pass onto the deploy.sh script (like the username/password)" >&2
  exit 2
fi

MODULE="$1"
WD=`dirname $0`
DEPLOY="$WD/deploy.sh"

shift

if [ "$MODULE" = "list" ]
then
  "$DEPLOY" "$@" list-modules
  exit 0
fi

if "$DEPLOY" "$@" list-modules | egrep -q "^  . $MODULE"
then
  exit 0
else
  exit 255
fi
Remember to make the isdeployed.sh script executable. You can do so by running from the command prompt: chmod a+x /path/to/geronimo/bin/isdeployed.sh

So now that you've setup the basics for Geronimo deployment you need to configure your project. First thing you need to do is change your build.xml file to the following:
<project name="MyEJBProject" default="default" basedir="." 
    ejbjarproject="http://www.netbeans.org/ns/j2ee-ejbjarproject/3">
  <description>Builds, tests, and runs the project MyEJBProject.</description>

  <import file="nbproject/build-impl.xml"/>
  <import file="geronimo-ant-deploy.xml"/>

  <target name="run-deploy" depends="dist,geronimo-deploy">
  </target>
</project
As you can see above, we include the geronimo-ant-deploy.xml (which has the necessary targets for deploying to Geronimo), and then we override "run-deploy" and configure it to first run "dist" so the JAR is built, and the the "geronimo-deploy" target.

Finally we need to configure the Geronimo deployment by setting some properties in your project. In the project's "nbproject" subdirectory, open the "project.properties" file. Then at the end add the following 3 properties:
deploy.module=${dist.jar}
deploy.plan=${meta.inf}/geronimo-ejb.xml
deploy.moduleId=user/MyEJBProject/1.0/jar
These properties are basically described as follows:
  • deploy.module - the path to that JAR archive you wish to deploy
  • deploy.plan - the path to your Geronimo deploy plan .xml file
  • deploy.moduleId - the module ID of your project. This is needed to check if a module is deployed or not. This is basically the moduleId as defined in your deploy plan, taking the form of: group/artifact/version/type
Once you've completed these steps you can use the standard Netbeans "Deploy" action to deploy your project to a local Geronimo instance.

Modifying for using in Windows
Since we need the "isdeployed.sh" script to check if a project is deployed, you can't run the above on Windows "as-is". You do have a couple of options though.

1. The easiest is probably to use the following "geronimo-ant-deploy.xml" file instead of the one given above:
<project name="geronimo-ant-deploy" default="geronimo-init" basedir=".">
  <dirname property="basedir.geronimo-ant-deploy" file="${ant.file.geronimo-ant-deploy}">

  <property file="nbproject/project.properties">
  <property file="${basedir.geronimo-ant-deploy}/geronimo-ant-deploy.properties">

  <target name="geronimo-init">
    <property name="geronimo.deploy-name" value="${deploy.moduleId} (${deploy.module})">

    <condition property="geronimo.init.dependencies-satisfied">
      <and>
        <isset property="deploy.plan">
        <isset property="deploy.module">
        <isset property="deploy.moduleId">
      </isset>
    </isset>

    <fail unless="geronimo.init.dependencies-satisfied">
      Failed to deploy:
      1. You need to set the deploy.plan property to the path to the deploy plan .xml file
         (Current Value: ${deploy.plan})
      2. You need to set the deploy.module property to the path to the module (archive) to deploy 
         (Current Value: ${deploy.module})
      3. You need to set the deploy.moduleId property to the Geronimo module ID for this project.
         You can find the required value for this in ${deploy.plan} (deploy.plan) as the <dep:moduleId> tag,
         and it would be in the form: groupId/artifactId/version/type
    </fail>
  </isset>

  <!-- UNDEPLOY -->
  <target name="geronimo-undeploy" depends="geronimo-init" 
      description="Undeploying webapp in geronimo entry point">
    <echo>Undeploying ${geronimo.deploy-name}</echo>

    <exec dir="${geronimo.home}" executable="${geronimo.bin}/${geronimo.deploy}" failonerror="true">
      <arg line="--user ${geronimo.user} --password ${geronimo.pwd} undeploy ${deploy.moduleId}">
    </arg>

    <echo>Undeployed ${geronimo.deploy-name}</echo>
  </exec>

  <!-- DEPLOY -->
  <target name="geronimo-deploy" depends="geronimo-undeploy" 
      description="Deploying webapp in geronimo entry point">
    <echo>Deploying new application ${geronimo.deploy-name}</echo>

    <exec dir="${geronimo.home}" executable="${geronimo.bin}/${geronimo.deploy}" failonerror="true">
      <arg line="--user ${geronimo.user} --password ${geronimo.pwd} deploy ${basedir}/${deploy.module} ${basedir}/${deploy.plan}">
    </arg>

    <echo>Deployed ${geronimo.deploy-name}</echo>
  </exec>
  </target>
</project>

2. Alternatively, to keep the conditional deploy/redeploy functionality might be desired, because they a redeploy executes in a single step. For this you can make your own Windows version of "isdeployed.sh" and then modify the appropriate targets in the build file to use your's instead. You can leave the script almost intact by using the Windows version of egrep. Though I'm not sure how you would return success/failure/error levels to ant. At the very least you can possibly return success/failure, which should be sufficient. For this you just need to check for "0" return code as "project is deployed" and all non-zero return codes as "not deployed".
My version above has 3 return levels which is "0" for "deployed", "255" for "not deployed" and any other code for "error". In case of an "error" I would cease the build process with a <fail> task, though this is not crucial for getting the script to run.

3. You can also use Cygwin to run the script inside a "virtual Unix" environment.

So, this is how I manage my Geronimo projects through Netbeans. If you get stuck, drop me a message and I'll see where I can help out.

Geronimo - Using Hibernate as your JPA provider

So we started a redev of a JavaEE project, and I decided to use Geronimo as the application server. Geronimo uses OpenEJB for it's EJB container, and I guess this was my biggest motivator. OpenEJB is truly a brilliant project. I also replaced Toplink with Hibernate for the persistence.

The justification of Hibernate was definitely maturity. It's much faster that EclipseLink/Toplink and definitely less buggy. I've had too many problems with Toplink to ever willingly use it again where I have a better option. To get Hibernate integrated into Geronimo wasn't easy though. It's the first time I use Geronimo to this degree. Previously I just ported a small project to Geronimo which had nothing more than a JMS queue and an MDB. To get Hibernate running in Geronimo isn't difficult, though I didn't know how, and thus struggled a bit. So this entry will be my second one describing how to use a specific persistence framework in OpenEJB.

Deploying Hibernate in Geronimo
The basic idea on using Hibernate is too deploy the dependencies and setup a special transaction manager. This explanation was based on Hibernate 3.3. So first get hold of:
  • Hibernate Distribution 3.3.2
  • Hibernate Annotations 3.4.0, and
  • Hibernate EntityManager 3.4.0
Then extract the archives, and retrieve from the extracted directories the following JAR files. I recommend you copy them into a temporary directory for easier maintenance while deploying Hibernate as a JPA provider.
  • Hibernate Distribution
    1. hibernate3.jar
    2. lib/required/antlr-2.7.6.jar
    3. lib/required/commons-collections-3.1.jar
    4. lib/required/dom4j-1.6.1.jar
    5. lib/required/javassist-3.9.0.GA.jar
    6. lib/required/jta-1.1.jar
    7. lib/required/slf4j-api-1.5.8.jar
  • Hibernate Annotations
    1. hibernate-annotations.jar
    2. lib/ejb3-persistence.jar
    3. lib/hibernate-commons-annotations.jar
    4. lib/slf4j-api.jar
  • Hibernate EntityManager
    1. hibernate-entitymanager.jar
Since the current Geronimo (2.1) uses OpenEJB 3.0, you need to create a Hibernate Transaction Manager Lookup class and add it as a dependency to be used wherever we use Hibernate. For this I'll explain how to do it as you would in Netbeans. If you use another development method/IDE, adapt appropriately.
  1. Start a new Java Class Library project and call it GeronimoTransactionManager.
  2. Create a class "org.hibernate.transaction.GeronimoTransactionManagerLookup".
  3. Paste the following code into this new class.
    package org.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;
    }
    }
  4. Then under the project's properties, make sure "JDK 5" is selected in the "Source/Binary Format" drop down on the "Sources" property page.
  5. Before closing the project properties dialog, goto Libraries and add all the Hibernate JAR files we listed above to your classpath by clicking the "Add JAR/Folder" button and selecting all of them. If you are using Netbeans you might already have a "Hibernate JPA" library configured in the IDE, so in this case you can instead click the "Add Library" button and select "Hibernate JPA" from the list. We only need the our class to compile against Hibernate, so it doesn't matter if you don't use the exact version we will be deploying into Geronimo. As long as the API is the same, you should be able to safely compile against any Hibernate 3.3 JARs.
  6. Then you need to add one more JAR as a library. This will be the Geronimo kernel jar, which you can find in the Geronimo distribution directory under: repository/org/apache/geronimo/framework/geronimo-kernel/2.1.4/geronimo-kernel-2.1.4.jar
  7. Confirm the properties dialog by pressing the "OK" button.
  8. Now build the project and find the GeronimoTransactionManager.jar file in the project's "dist" directory.
  9. This is the JAR we will use when adding repository resources to Geronimo in the next step, so put it with the rest of the Hibernate JAR files you collected above.
Now we will deploy the resources to Geronimo. When you add a JAR resource, you do so on the web console under the Services->Repository portlet. You select the JAR file by clicking the 'Browse' button and then enter the 4 details, nl. Group, Artifact, Version and Type. After you've added it, Geronimo will add them to it's "repository" as: group/artifact/version/type/{artifact}-{version}.jar. Internally it's ID will be "group/artifact/version/type". I will use this format when referring to them, so upload each of the following JAR files using this format to determine which values should go into each field.
  • hibernate3.jar - hibernate/core/3.3/jar
  • lib/required/antlr-2.7.6.jar - hibernate/antlr/2.7.6/jar
  • lib/required/commons-collections-3.1.jar - hibernate/commons-collections/3.1/jar
  • lib/required/dom4j-1.6.1.jar - hibernate/dom4j/1.6.1/jar
  • lib/required/javassist-3.9.0.GA.jar - hibernate/javassist/3.9.0.GA/jar
  • lib/required/jta-1.1.jar - hibernate/jta/1.1/jar
  • hibernate-annotations.jar - hibernate/annotations/3.4/jar
  • lib/ejb3-persistence.jar - hibernate/jpa/3.0/jar
  • lib/hibernate-commons-annotations.jar - hibernate/commons-annotations/3.4/jar
  • hibernate-entitymanager.jar - hibernate/entitymanager/3.4/jar
  • GeronimoTransactionManager.jar - hibernate/GeronimoTransactionManager/1.0/jar
Now that you've setup all the dependencies you can create your EJB project. All you need to do is
  1. Create a JDBC pool through the Geronimo console (in this example called: console.dbpool/jdbc_myDatabasePool/1.0/rar)
  2. List the following dependencies in your EJB project's deploy plan (geronimo-ejb.xml):
    • Your JDBC pool
    • All the Hibernate dependencies we added above
    • Geronimo's "slf4j-api" dependency in your deploy plan.In Geronimo 2.1.4 it's called: org.slf4j/slf4j-api/1.4.3/jar
    You can goto the Service->Repository portlet and click on a resource to see it's usage. When building a deploy plan it's the quickest way to add dependencies. Would be great if the Geronimo developers can make a generic dependency builder to generate the deploy plan, like the one they have when building WAR deploy plans. You EJB deploy plan would look something like this:
    <?xml version="1.0" encoding="UTF-8"?>
    <openejb-jar xmlns="http://openejb.apache.org/xml/ns/openejb-jar-2.2"
    xmlns:naming="http://geronimo.apache.org/xml/ns/naming-1.2"
    xmlns:sec="http://geronimo.apache.org/xml/ns/security-2.0"
    xmlns:dep="http://geronimo.apache.org/xml/ns/deployment-1.2">

    <dep:environment>
    <dep:moduleId>
    <dep:groupId>user</dep:groupId>
    <dep:artifactId>MyHibernateEJB</dep:artifactId>
    <dep:version>1.0</dep:version>
    <dep:type>jar</dep:type>
    </dep:moduleId>

    <dep:dependencies>
    <dep:dependency>
    <dep:groupId>console.dbpool</dep:groupId>
    <dep:artifactId>jdbc_myDatabasePool</dep:artifactId>
    <dep:version>1.0</dep:version>
    <dep:type>rar</dep:type>
    </dep:dependency>
    <dep:dependency>
    <dep:groupId>hibernate</dep:groupId>
    <dep:artifactId>core</dep:artifactId>
    <dep:version>3.3</dep:version>
    <dep:type>jar</dep:type>
    </dep:dependency>
    <dep:dependency>
    <dep:groupId>hibernate</dep:groupId>
    <dep:artifactId>annotations</dep:artifactId>
    <dep:version>3.4</dep:version>
    <dep:type>jar</dep:type>
    </dep:dependency>
    <dep:dependency>
    <dep:groupId>hibernate</dep:groupId>
    <dep:artifactId>antlr</dep:artifactId>
    <dep:version>2.7.6</dep:version>
    <dep:type>jar</dep:type>
    </dep:dependency>
    <dep:dependency>
    <dep:groupId>hibernate</dep:groupId>
    <dep:artifactId>commons-annotations</dep:artifactId>
    <dep:version>3.4</dep:version>
    <dep:type>jar</dep:type>
    </dep:dependency>
    <dep:dependency>
    <dep:groupId>hibernate</dep:groupId>
    <dep:artifactId>commons-collections</dep:artifactId>
    <dep:version>3.1</dep:version>
    <dep:type>jar</dep:type>
    </dep:dependency>
    <dep:dependency>
    <dep:groupId>hibernate</dep:groupId>
    <dep:artifactId>dom4j</dep:artifactId>
    <dep:version>1.6.1</dep:version>
    <dep:type>jar</dep:type>
    </dep:dependency>
    <dep:dependency>
    <dep:groupId>hibernate</dep:groupId>
    <dep:artifactId>entitymanager</dep:artifactId>
    <dep:version>3.4</dep:version>
    <dep:type>jar</dep:type>
    </dep:dependency>
    <dep:dependency>
    <dep:groupId>hibernate</dep:groupId>
    <dep:artifactId>javassist</dep:artifactId>
    <dep:version>3.9.0.GA</dep:version>
    <dep:type>jar</dep:type>
    </dep:dependency>
    <dep:dependency>
    <dep:groupId>hibernate</dep:groupId>
    <dep:artifactId>jpa</dep:artifactId>
    <dep:version>3.0</dep:version>
    <dep:type>jar</dep:type>
    </dep:dependency>
    <dep:dependency>
    <dep:groupId>hibernate</dep:groupId>
    <dep:artifactId>jta</dep:artifactId>
    <dep:version>1.1</dep:version>
    <dep:type>jar</dep:type>
    </dep:dependency>
    <dep:dependency>
    <dep:groupId>hibernate</dep:groupId>
    <dep:artifactId>GeronimoTransactionManager</dep:artifactId>
    <dep:version>1.0</dep:version>
    <dep:type>jar</dep:type>
    </dep:dependency>
    <dep:dependency>
    <dep:groupId>org.slf4j</dep:groupId>
    <dep:artifactId>slf4j-api</dep:artifactId>
    <dep:version>1.4.3</dep:version>
    <dep:type>jar</dep:type>
    </dep:dependency>
    </dep:dependencies>
    </dep:environment>
    </openejb-jar>
  3. Specify the transaction manager in your persistence.xml. Here is an example. Note how the JTA data source is specified by only using the artifact ID of the pool you created, with any underscore (_) characters replaced with a "/". This is how Geronimo maps repository resource's module IDs to JNDI names.
    <?xml version="1.0" encoding="UTF-8"?>
    <persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
    <persistence-unit name="MyHibernateEJB-PU" transaction-type="JTA">
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
    <jta-data-source>jdbc/myDatabasePool</jta-data-source>
    <exclude-unlisted-classes>false</exclude-unlisted-classes>
    <properties>
    <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
    <property name="hibernate.transaction.manager_lookup_class"
    value="org.hibernate.transaction.GeronimoTransactionManagerLookup"/>
    </properties>
    </persistence-unit>
    </persistence>
  4. And deploy your EJB.
All should be done now, and you can use Hibernate like you would any other persistence framework.