Home » Java » Enterprise Java » JPA persistence.xml SQL script definitions

About Sebastian Daschner

Sebastian Daschner
Sebastian Daschner is a self-employed Java consultant and trainer. He is the author of the book 'Architecting Modern Java EE Applications'. Sebastian is a Java Champion, Oracle Developer Champion and JavaOne Rockstar.

JPA persistence.xml SQL script definitions

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="http://xmlns.jcp.org/xml/ns/persistence"
    <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.schema-generation.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

Published on Java Code Geeks with permission by Sebastian Daschner, partner at our JCG program. See the original article here: JPA persistence.xml SQL script definitions

Opinions expressed by Java Code Geeks contributors are their own.

(0 rating, 0 votes)
You need to be a registered member to rate this.
Start the discussion Views Tweet it!
Do you want to know how to develop your skillset to become a Java Rockstar?
Subscribe to our newsletter to start Rocking right now!
To get you started we give you our best selling eBooks for FREE!
1. JPA Mini Book
2. JVM Troubleshooting Guide
3. JUnit Tutorial for Unit Testing
4. Java Annotations Tutorial
5. Java Interview Questions
6. Spring Interview Questions
7. Android UI Design
and many more ....
I agree to the Terms and Privacy Policy
Notify of

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Inline Feedbacks
View all comments