Skip to content

Batoo JPA on JBoss 7.x

hceylan edited this page Jan 30, 2013 · 1 revision

To be able to use Batoo JPA on JBoss 7.x you need to declare create JBoss module. The steps to create the module is given below.

Create directory

$JBOSS_HOME/modules/org/batoo/main

Drop these files there

  • antlr-runtime-3.4.jar
  • batoo-jpa-2.0.1.jar (or whatever version you are using)
  • bonecp-0.7.1.RELEASE.jar
  • commons-db-utils-1.4.jar

Create module.xml

<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.1" name="org.batoo">
    <resources>
        <resource-root path="batoo-jpa-2.0.1.jar"/>
        <resource-root path="commons-dbutils-1.4.jar"/>
        <resource-root path="bonecp-0.7.1.RELEASE.jar"/>
        <resource-root path="antlr-runtime-3.4.jar"/>
    </resources>
    <dependencies>
        <module name="asm.asm"/>
        <module name="com.google.guava"/>
        <module name="javax.persistence.api"/>
        <module name="javax.transaction.api"/>
        <module name="javax.validation.api"/>
        <module name="javax.xml.bind.api"/>
        <module name="org.apache.commons.collections"/>
        <module name="org.apache.commons.beanutils"/>
        <module name="org.apache.commons.lang"/>
        <module name="org.apache.commons.pool"/>
        <module name="org.apache.commons.io"/>
        <module name="org.slf4j"/>
        <module name="org.jboss.as.jpa.spi" />
        <module name="org.jboss.jandex" />
    </dependencies>
</module>

The name of the jar files must match the declarations in the module.xml, therefore you need to make modifications to resource-root declarations if the name of the files differ in the directory or if you are using a different Batoo JPA version.

Edit your persistence.xml file

<?xml version="1.0" encoding="UTF-8"?>
<persistence ...>
   <persistence-unit ...>
      <!-- set the provider to batoo: -->
       <provider>org.batoo.jpa.core.BatooPersistenceProvider</provider>

       <properties>
             <!-- JBOSS-specific: tell jboss, in which module it finds the batoo classes: -->
             <property name="jboss.as.jpa.providerModule" value="org.batoo"/>

            ... other batoo properties if any ...
            <property name="org.batoo.jpa.ddl" value="NONE" />

            ... other properties if any ...

       </properties>

   </persistence-unit>
</persistence>