Search code examples
jpaeclipselinkwebsphere-libertyopen-liberty

Using Open Liberty with EclipseLink JPA provider - javax.persistence.sql-load-script-source not loading


Using Open Liberty version 21.0.0.12 with jpa-2.2 configured among features and Derby DS config:

server.xml

  <featureManager>
    <feature>jaxrs-2.1</feature>
    <feature>jsonp-1.1</feature>
    <feature>cdi-2.0</feature>
    <feature>mpConfig-2.0</feature>
    <feature>jpa-2.2</feature>
  </featureManager>

  ...

  <dataSource jndiName="jdbc/JakartaEECafeDB">
    <jdbcDriver libraryRef="derbyJDBCLib" />
    <properties.derby.embedded databaseName="jakartaee-cafe-data" createDatabase="create"/>
  </dataSource>

and with my persistence.xml defined with:

persistence.xml

<persistence version="2.2"
xmlns="http://xmlns.jcp.org/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence
                        http://xmlns.jcp.org/xml/ns/persistence/persistence_2_2.xsd">
<persistence-unit name="coffees" transaction-type="JTA">
    <jta-data-source>jdbc/JakartaEECafeDB</jta-data-source>
    <exclude-unlisted-classes>false</exclude-unlisted-classes>

    <properties>
        <property
            name="javax.persistence.schema-generation.database.action"
            value="drop-and-create" />
        <property name="javax.persistence.sql-load-script-source"
            value="META-INF/initial-data.sql" />
        <property name="eclipselink.ddl-generation" value="create-tables"/>
        <property name="eclipselink.logging.level.sql" value="FINE" />
        <property name="eclipselink.logging.parameters" value="true" />
        <property name="hibernate.show_sql" value="true" />
    </properties>
  </persistence-unit>
</persistence>

my initial-data.sql script doesn't seem to get loaded. The DB tables seem to get created but they are empty; my script populated them with INSERT(s) doesn't seem to get run, and no obvious error appears even when turning Open Liberty JPA tracing on.


Solution

  • Delete EclipseLink persistence property getting in the way

    For me the solution was to delete the extra property: <property name="eclipselink.ddl-generation" value="create-tables"/>

    Apparently it conflicted with the "javax.persistence.schema-generation.database.action" somehow?

    So it works to just have:

    <persistence-unit name="coffees" transaction-type="JTA">
        <jta-data-source>jdbc/JakartaEECafeDB</jta-data-source>
        <exclude-unlisted-classes>false</exclude-unlisted-classes>
    
        <properties>
            <property
                name="javax.persistence.schema-generation.database.action"
                value="drop-and-create" />
            <property name="javax.persistence.sql-load-script-source"
                value="META-INF/initital-data.sql" />
            <!-- Delete
            <property name="eclipselink.ddl-generation" value="create-tables"/>
              -->
            ...