I had been struggling with this feature for a few days and finally figured it
out.  Since none of the posts that I found in my many searches led me to the
resolution, I thought I would post what I was doing wrong and what I did to
fix it.

Our project is required to generate the SQL scripts to create the schema for
our 6 supported database vendors at build time.  So I edited the ANT script
used to build the project and added the following target:
<target name="jpa_generate_sqlscripts">
        <mkdir dir="schema/${vendor}"/>
        <taskdef name="mappingtool"
classname="org.apache.openjpa.jdbc.ant.MappingToolTask"
classpathref="classpath.openjpa"/>
        
        <mappingtool action="buildSchema"
sqlFile="${basedir}/schema/${vendor}/create.sql">
                <config DBDictionary="${vendor}"
propertiesFile="META-INF/persistence.xml"/>
                <classpath>
                        <path refid="classpath.openjpa"/>
                        <pathelement location="bin"/>
                </classpath>
        </mappingtool>
</target>

I then added antcalls to my new target like this:
<antcall target="jpa_generate_sqlscripts">
        
</antcall>
... and so forth for the 5 other vendors.

After careful scrutiny of the documentation of the options/flags for the
Mapping Tool
(http://openjpa.apache.org/builds/1.2.1/apache-openjpa-1.2.1/docs/manual/manual.html#ref_guide_mapping_mappingtool),
I realized that "buildSchema" is the default value for the action attribute,
so I omitted it.  And then looking at the documentation of the options for
the Schema Tool
(http://openjpa.apache.org/builds/1.2.1/apache-openjpa-1.2.1/docs/manual/manual.html#ref_guide_schema_schematool)
I saw that "add" is the default action, but what I need is "build", so I
added the schemaAction attribute and set its value to "build".

At this point I thought I had it for sure.  But, the tool still tried to
connect to the database but failed because I didn't specify a
ConnectionDriverName (or any other connection details for that matter).

Finally, I saw that there is an argument named "readSchema".  This is a
boolean flag and the documentation doesn't say which is the default value. 
But after I set this option to false in my ANT script, the tool succeeded.
This is the final ANT target:
<target name="jpa_generate_sqlscripts">
        <mkdir dir="schema/${vendor}"/>
        <taskdef name="mappingtool"
classname="org.apache.openjpa.jdbc.ant.MappingToolTask"
classpathref="classpath.openjpa"/>
        
        <mappingtool schemaAction="build"
sqlFile="${basedir}/schema/${vendor}/create.sql" readSchema="false">
                <config DBDictionary="${vendor}"
propertiesFile="META-INF/persistence.xml"/>
                <classpath>
                        <path refid="classpath.openjpa"/>
                        <pathelement location="bin"/>
                </classpath>
        </mappingtool>
</target>


Marc Boudreau
-- 
View this message in context: 
http://n2.nabble.com/Generating-DDL-without-connecting-to-Database-OpenJPA-1-2-1-tp3731174p3731174.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

Reply via email to