0

I need to fill my database on ear startup, so I add javax.persistence.sql-load-script-source tag with reference to the file.

<persistence-unit name="MyPU" transaction-type="JTA">
    <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
    <jta-data-source>java:/jboss/datasource/mydatasource</jta-data-source>
    <jar-file>Entities.jar</jar-file>
    <exclude-unlisted-classes>false</exclude-unlisted-classes>
    <properties>
        <property name="javax.persistence.schema-generation.database.action" value="create"/>
        <property name="eclipselink.logging.logger" value="org.eclipse.persistence.logging.DefaultSessionLog"/>
        <property name="eclipselink.logging.level" value="ALL"/>
        <property name="eclipselink.logging.level.sql" value="ALL"/>
        <property name="javax.persistence.sql-load-script-source" value="META-INF/defaultdata.sql"/>
        <property name="javax.persistence.sql-load-script-source" value="META-INF/insertnations.sql"/>
    </properties>
</persistence-unit>

It works, but now i want to use two file because i want to separate "most static" data (like nations and regions of the world) from "per-deploy" data (like some configurations).

Using the tag twice not works. Is there something wrong? It is possible to do what i want?

The persistence unit is used in a EAR. I use Wildfly and eclipselink 2.5.2 as persistence provider

Daniele Licitra
  • 1,520
  • 21
  • 45
  • You can use javax.persistence.schema-generation.create-script-source alongwith load data. I dont think there is option to allow multiple files for load create or drop script. – Acewin Nov 14 '16 at 17:46
  • What you can do is run the additional script from your code. But there is catch there as well. EntityManager does not allow loading script through file. You will have to read the content into a string to be able to run through entitymanager. Or use JDBC script runner – Acewin Nov 14 '16 at 17:55
  • You can call Persistence.generateSchema("MyPU", properties); repeatedly, passing in "javax.persistence.sql-load-script-source" with different file values. Unfortunately Maps and properties don't allow multiple key values, which is why you'll have to make multiple calls to execute multiple files, or pass in an java.io.Reader that reads/concatenates all the scripts you want executed – Chris Nov 15 '16 at 01:01

0 Answers0