So, I'm hoping this is a simple question. I've downloaded openjpa-all-2.3.0.jar (and mysql-connector-java-5.1.31-bin.jar) So, I have this as my build.xml
<?xml version="1.0" ?>
<project name="reverser" default="reversemap" basedir=".">
<taskdef name="reversemappingtool" classname="org.apache.openjpa.jdbc.ant.ReverseMappingToolTask">
<classpath>
<pathelement location="${basedir}/mysql-connector-java-5.1.31-bin.jar" />
<pathelement location="${basedir}/openjpa-all-2.3.0.jar" />
</classpath>
</taskdef>
<target name="reversemap">
<reversemappingtool package="com.whatever.dbresults" directory="${basedir}/src" customizerProperties="${basedir}/conf/reverse.properties" metadata="none" generateAnnotations="true" />
</target>
</project>
In my reverse.properties file, I have:
ConnectionDriverName=com.mysql.jdbc.Driver
ConnectionDriverURL=jdbc:mysql://localhost:3306/db
ConnectionUser=user
ConnectionPassword=pw
when I run it tho, I get:
/tmp/apache-openjpa-2.3.0/build.xml:10: <openjpa-2.3.0-r422266:1540826 fatal user error> org.apache.openjpa.util.UserException: The persistence provider is attempting to use properties in the persistence.xml file to resolve the data source. A Java Database Connectivity (JDBC) driver or data source class name must be specified in the openjpa.ConnectionDriverName or javax.persistence.jdbc.driver property. The following properties are available in the configuration: "org.apache.openjpa.jdbc.conf.JDBCConfigurationImpl@ec63420c".
at org.apache.openjpa.jdbc.schema.DataSourceFactory.newDataSource(DataSourceFactory.java:72)
at org.apache.openjpa.jdbc.conf.JDBCConfigurationImpl.createConnectionFactory(JDBCConfigurationImpl.java:849)
at org.apache.openjpa.jdbc.conf.JDBCConfigurationImpl.getConnectionFactory(JDBCConfigurationImpl.java:732)
at org.apache.openjpa.jdbc.conf.JDBCConfigurationImpl.getDataSource(JDBCConfigurationImpl.java:878)
at org.apache.openjpa.jdbc.conf.JDBCConfigurationImpl.getDataSource2(JDBCConfigurationImpl.java:920)
at org.apache.openjpa.jdbc.schema.SchemaGenerator.<init>(SchemaGenerator.java:85)
at org.apache.openjpa.jdbc.meta.ReverseMappingTool.run(ReverseMappingTool.java:2009)
at org.apache.openjpa.jdbc.ant.ReverseMappingToolTask.executeOn(ReverseMappingToolTask.java:295)
This is probably the wrong way of debugging this problem, but tracked the properties file being loaded, at ReverseMappingToolTask.java line 282, and it then passes that to
flags.customizer.setConfiguration(customProps);
before calling
ReverseMappingTool.run(conf, files, flags, loader);
The error tho, seems to happen at line 2009 of ReverseMappingTool, at a point where it never seems to even touch the "flags".
Well. My "debugging" is probably a non-sequitur/red-herring/what have you. How can I get the reverse mapping to work in the simplest way possible? I just want to use it with ant, and not maven, etc.
EDIT 2014-08-13 OK, I managed to move the error along by changing my build.xml to
<?xml version="1.0" ?>
<project name="reverser" default="reversemap" basedir=".">
<taskdef name="reversemappingtool" classname="org.apache.openjpa.jdbc.ant.ReverseMappingToolTask">
<classpath>
<pathelement location="${basedir}/mysql-connector-java-5.1.31-bin.jar" />
<pathelement location="${basedir}/openjpa-all-2.3.0.jar" />
</classpath>
</taskdef>
<target name="reversemap">
<reversemappingtool package="com.whatever.dbresults" directory="${basedir}/src" metadata="none" generateAnnotations="true">
<config
connectionDriverName="com.mysql.jdbc.Driver"
connectionURL="jdbc:mysql://localhost:3306/db"
connectionUserName="user"
connectionPassword="pw"
/>
</reversemappingtool>
</target>
</project>
But, then now, I get:
<openjpa-2.3.0-r422266:1540826 fatal user error> org.apache.openjpa.util.MetaDataException: MetaDataFactory could not be configured (conf.newMetaDataFactoryInstance() returned null). This might mean that no configuration properties were found. Ensure that you have a META-INF/persistence.xml file, that it is available in your classpath, or that the properties file you are using for configuration is available. If you are using Ant, please see the <properties> or <propertiesFile> attributes of the task's nested <config> element. This can also occur if your OpenJPA distribution jars are corrupt, or if your security policy is overly strict.
Thanks!
OK, well, I finally got it working. Of course, I don't know if this is the "right" way or not. But, it generates my classes, and that's really all I wanted.
So, my new build file looks like this:
<?xml version="1.0" ?>
<project name="reverser" default="reversemap" basedir=".">
<taskdef name="reversemappingtool" classname="org.apache.openjpa.jdbc.ant.ReverseMappingToolTask">
<classpath /> <!-- removed classpath for the sake of making this post short -->
</taskdef>
<target name="reversemap">
<reversemappingtool package="com.whatever.db" directory="${basedir}/src" metadata="none" generateAnnotations="true">
<config propertiesFile="persistence.xml" />
</reversemappingtool>
</target>
</project>
And, my persistence.xml looks like
<?xml version="1.0"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="2.0">
<persistence-unit name="openjpa">
<provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
<properties>
<property name="openjpa.ConnectionURL" value="jdbc:mysql://localhost:3306/db"/>
<property name="openjpa.ConnectionDriverName" value="com.mysql.jdbc.Driver"/>
<property name="openjpa.ConnectionUserName" value="user"/>
<property name="openjpa.ConnectionPassword" value="password"/>
<property name="openjpa.Log" value="DefaultLevel=WARN, Tool=INFO"/>
</properties>
</persistence-unit>
</persistence>
So. I think that does it. Hopefully if someone else comes along and wants to know how to do reversemap with just ant and java, this will help.