Versions Compared

Key

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

...

Code Block
        <path id="jpa.enhancement.classpath">
            <pathelement location="bin"/>

            <!-- lib contains all of the jars that came with the OpenJPA binary download -->
            <fileset dir="lib">
                <include name="**/*.jar"/>
            </fileset>
        </path>


        <target name="enhance" depends="build">
        <!-- This is a bit of a hack, but I needed to copy the persistence.xml file from my src dir
            to the build dir when we run enhancement -->
        <copy includeemptydirs="false" todir="bin">
            <fileset dir="src" excludes="**/*.launch, **/*.java"/>
        </copy>


        <!-- define the openjpac task -->
        <taskdef name="openjpac" classname="org.apache.openjpa.ant.PCEnhancerTask">
            <classpath refid="jpa.enhancement.classpath"/>
        </taskdef>
            
        <!-- invoke enhancer the enhancer -->
        <openjpac>
            <classpath refid="jpa.enhancement.classpath"/>
        </openjpac>
        <echo message="Enhancing complete."/>
    </target>

The persistence.xml doesn't have to be complete. The required elements are the persistence-unit (any legal name will do), and the provider (you have to identify openjpa). You can identify the classes to be enhanced either in this file or in the enhancer task ant project.

Code Block

<?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="enhance" transaction-type="RESOURCE_LOCAL">
    <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
    <class>com.egg.sample.model.Employee</class>
  </persistence-unit>
</persistence>