Well,
this is the first solution I found for getting entity
enhanced via the openjpac /
org.apache.openjpa.ant.PCEnhancerTask ant task. This
solution now works just for project in category "Java
Application" and "Java Class Library". I'm still at work to
have it working in "Web Application" projects. Anyway hope
tha can be helpfull to someone.
This tha follows is the target I add to
<PROJECT_BASE_DIR>/build.xml
<!-- where OpenJPA jars are in the filesystem, set
accordingly to where you put yours -->
<property name="jpa-home"
value="${user.home}/NetBeansProjects/java-libraries/apache-openjpa-1.0.1"/>
<path id="jpa.classpath">
<pathelement path="${jpa-home}/openjpa-1.0.1.jar"/>
<fileset dir="${jpa-home}/lib">
<include name="*.jar"/>
</fileset>
</path>
<taskdef name="openjpac"
classname="org.apache.openjpa.ant.PCEnhancerTask">
<classpath refid="jpa.classpath"/>
</taskdef>
<target name="jpa-enhance" depends="compile">
<property name="jpa-home"
value="${user.home}/NetBeansProjects/java-libraries/apache-openjpa-1.0.1"/>
<openjpac>
<!-- classpath where the tool look for classes to
enhance. This is the default location in a NB project
directory layout where classes are built -->
<classpath>
<pathelement
location="${basedir}/build/classes"/>
</classpath>
<!-- I put it in here. See below the
persistence.xml file -->
<config
propertiesFile="${basedir}/src/conf/persistence.xml"/>
</openjpac>
</target>
----------------------- persistence.xml
-------------------------------
<?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="TestApp2PU"
transaction-type="JTA">
<provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
<!-- one class element for each class to be enhanced -->
<class>model.Visitor</class>
<class>model.....</class>
<properties>
<property name="openjpa.ConnectionFactoryName"
value="java:comp/env/jdbc/pippo"/>
<property name="openjpa.TransactionMode"
value="local"/>
<property name="openjpa.jdbc.SynchronizeMappings"
value="buildSchema(ForeignKeys=true)"/>
<property name="openjpa.jdbc.DBDictionary"
value="postgres"/>
<property name="openjpa.Log"
value="DefaultLevel=INFO,Runtime=INFO,Query=INFO,JDBC=INFO,SQL=INFO"/>
<property name="openjpa.jdbc.SynchronizeMappings"
value="buildSchema(ForeignKeys=true)"/>
</properties>
</persistence-unit>
</persistence>
Now, when I do "Clean and Build" on the project everithing
is compiled and @Entity classes are enhaced.
What to do to have it working in a web app using NB? Well,
at this time the way I'm using is just putting the generated
jar file in the web project library and it works.
Andrea Martano
--------------
LiteHouse srl
Milano - Italy