Reputation: 2741
You can in the persistance.xml set tables to be dropped and recreated on startup. Is it possible to be more selective having some tables stay populated and others recreated?
Upvotes: 0
Views: 2421
Reputation: 8229
Fortunately such feature (and even more) is supported starting from JPA 2.1 by using the following set of properties:
<property name="javax.persistence.schema-generation.database.action"
value="drop-and-create"/>
<property name="javax.persistence.schema-generation.create-source"
value="script"/>
<property name="javax.persistence.schema-generation.drop-source"
value="script"/>
<property name="javax.persistence.schema-generation.drop-script-source"
value="META-INF/drop-script.sql"/>
<property name="javax.persistence.schema-generation.create-script-source"
value="META-INF/create-script.sql"/>
<property name="javax.persistence.sql-load-script-source"
value="META-INF/load-script.sql"/>
In the above example javax.persistence.schema-generation.drop-source
informs provider to use scripts for creating, deleting or loading the database schema specified in the corresponding property values:
DROP TABLE ...
statementsCREATE TABLE ...
statementsINSERT INTO ...
statementsI hope it helps.
Upvotes: 1