Multiple SQL Load Scripts


SQL files can get extremely large and therefore are very difficult to maintain. In the projects I work, we tend to do database-driven localization for example, so you can imagine the amount of SQL statements.

Normally, you specify the load script for the drop-and-create goal in the persistence.xml with:

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

Where ${} is substituted by Maven for a specific profile:


Unfortunately, you cannot specify just a folder which contains multiple SQL files but have to point to a single SQL.

So how can we split the masterdata.sql into several mutliple SQL files?

We concatenate multiple smaller sql files to one large sql files, which will get executed if the specific profile is selected.

How do we do this?

With a specific maven plugin, namely org.zcore.maven - merge-maven-plugin

I suggest that you add add the plugin to your specific build profile and not globally since the downside to this approach is the increased build time due to the merge:


The important part is the location of the single combined file which is indicated with <target></target> and must reflect the file as specified with ${}. This example shows a web application which will move all the resources to META-INF.

Finally, you specify the source files which will be merged by <source></source>. In this example we specify each SQL file explicitly since order sometimes matter.