sebastiandaschner blog

JPA persistence.xml SQL script definitions

#javaee monday, december 04, 2017

You can define and link to SQL scripts in a JPA persistence context definition that will be executed at runtime. There are standardized properties to define scripts how to create the schema, bulk-load data and drop the schema, respectively:

<persistence version="2.1" xmlns=""
    <persistence-unit name="prod" transaction-type="JTA">

            <property name="javax.persistence.schema-generation.database.action"

            <property name="javax.persistence.schema-generation.create-script-source"
                    value="create-schema.sql" />

            <property name="javax.persistence.sql-load-script-source"
                    value="load-data.sql" />

            <property name="javax.persistence.schema-generation.drop-script-source"
                    value="drop-schema.sql" />


The SQL files are expected to reside in the classpath.

This post was reposted from my newsletter issue 004


Found the post useful? Subscribe to my newsletter for more free content, tips and tricks on IT & Java: