This should be possible by running org.apache.openjpa.jdbc.meta.MappingTool as a Java application using command line options like "-schemaAction add -sql update.sql". For more info see the forward mapping chapter of the manual at http://openjpa.apache.org/builds/2.4.0/apache-openjpa/docs/manual.html#ref_guide_mapping_mappingtool
Alternatively, there exist external tools that let you compare the schema of two different databases and generate update scripts. The advantage of using such a tool is that (as far is I know) OpenJPA will not generate some SQL, e.g. to drop columns that you have deleted. What I usually do is: run my application on a development database o that OpenJPA automatically updates the database schema. I then use this tool to compare the schema of this generated database with (a copy of) the live database. (To be really sure we are still using the same schema that OpenJPA would generate, I often also run one of our "unit" tests that uses OpenJPA on an empty database.) I then copy/paste the schema update script to a file and add any manual SQL to e.g. set default values for new columns. Be sure to run your final update script on a copy of the live database and verify everything works. Henno Vermeulen -----Oorspronkelijk bericht----- Van: kkharlin [mailto:[email protected]] Verzonden: maandag 31 augustus 2015 12:55 Aan: [email protected] Onderwerp: SchemaTool events on columns modification Hello, We use OpenJPA 2.2.2 and want to implement some sort of automigration mechanism in our product. The goal is to find out the columns that were added (fields were added in entities). As I understood OpenJPA use SchemaTool's "addColumn" method to add new column to the DB during EM initialization. Is there any easy way to catch such cases (kind of events or smth) without forking and modifying this tool? Now we have one solution: reflect on DB and get schema as XML files before and after EM initialization and make a diff to find the columns that were added. But we have a big DB schema and these two reflections take almost 2 minutes on solution start :( Any suggestions are appreciated. Thank you. -- View this message in context: http://openjpa.208410.n2.nabble.com/SchemaTool-events-on-columns-modification-tp7588470.html Sent from the OpenJPA Users mailing list archive at Nabble.com.
