I'm currently using EclipseLink 2.2 with HSQLDB 2.2 for an embedded file db. I've defined the structure of the db by using JPA annotations. The problem I have now is, that updating the structure (class members/annotations) will be not reflected in the db structure.
Via eclipselink.ddl-generation setting I can create the db completly new, but I want to keep the old data and just "update" the structure.
I found this feature in ObjectDB as "Automatic Schema Evolution" and it's described as following:
For every field in the new schema for which there is a matching field in the old schema, the new field in the new entity object is initialized using the value of the matching old field in the original entity object.
Fields in the new schema that do not have matching fields in the old schema are initialized with default values (0, false or null).
Fields in the old schema that do not have matching fields in the new schema are simply ignored (and their content is lost).
Also Hibernate has an option called hibernate.hbm2ddl.auto for updating the schema or validate it.
Is there a possibility to get my desired behavior, i.e. keeping the old data and update the structure?
Please log a enhancement request in EclipseLink for this feature and vote for it.
As a workaround you will need to ALTER your tables yourself to add any new columns. Generally migrating schema requires some work anyway, as new columns normally need the data defaulted to some value, etc.
Thank you James! I'll do that and hope a lot of people will vote
I already tried checking the schema validity myself, and i have some more questions:
How can I get (easily) the ddl for a specific class or just a field (except of letting eclipselink create a file with the schema). I saw there are classes like SchemaManager which are used for creation, but I couldn't figure out how to do that exactly.
The org.eclipse.persistence.tools.schemaframework package includes several classes for DDL generation. A TableDefinition can be used the create the DDL for a table.
The DefaultTableGenerator can generate a TableDefinition for an Entity class.