Play Evolution and JPA in Play Framework 2.4

I migrated the Play project from version 2.3.4 to 2.4.2. The projects use JPA (Hibernate) and Evolutions. I have a source Evolutions SQL script that populates a database with some sample data. This script now no longer works because Evolutions scripts are executed before Hibernate generates tables, which obviously leads to an error. Is this the desired behavior? Is there a way to change the execution order?

+7
hibernate jpa playframework playframework-evolutions
source share
1 answer

Evolution is creating and updating a database using simple SQL scripts. Therefore, if you use a framework that generates data tables themselves, for example, sleep mode, you need to turn off evolution (or turn off auto-generation and use only evolution).

Fill the database at startup

I have a similar problem with Cassandra, which I did - just create the code that reads the CQL file and execute it, and run this code after creating the actual data tables.

As I can see, Hibernate already has this function - you need to put your own SQL code in the /import.sql file at the root of your class path:

If a file named import.sql exists in the root directory of the class path ('/import.sql), then Hibernate will execute the SQL statements read from the file after creating the database schema.

0
source share

All Articles