tags:

views:

28

answers:

1

It is said that with the use of org.apache.openjpa.jdbc.ant.MappingToolTask it is possible to synchronize domain models classes with db schema. So by having following script as an Ant task i was able to add new columns to the given databases on the persistance.xml.

<target>
   <taskdef name="mappingtool" classpathref="maven.compile.classpath" classname="org.apache.openjpa.jdbc.ant.MappingToolTask" />
      <mappingtool schemaAction="refresh" >
      </mappingtool>
</target>

This script adds new columns every time i add a new attribute to the domain class. but it wont remove the corresponding column if i remove them from the domain class. Is there anyway to archive the synchronization for both (add/remove) with an single ant script?

A: 

Take a look through the user manual here and here.

  • refresh: Equivalent to retain, then add.
    • retain: Keep all schema components in the given XML definition, but drop the rest from the database. This action never adds any schema components.
    • add: This is the default action if you do not specify one. It brings the schema up-to-date with the given XML document by adding tables, columns, indexes, etc. This action never drops any schema components.

Perhaps try changing "refresh" to "drop,add".

Rick