将 Open Liberty 与 EclipseLink JPA 提供程序一起使用 - javax.persistence.sql-load-script-source 未加载

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

使用 Open Liberty 版本 21.0.0.12,在功能和 Derby DS 配置中配置 jpa-2.2

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>

我的 persistence.xml 定义为:

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>

我的 initial-data.sql 脚本似乎没有加载。数据库表似乎已创建,但它们是空的;我的脚本用 INSERT(s) 填充它们似乎没有得到 运行,即使打开 Open Liberty JPA 跟踪也没有出现明显的错误。

删除 EclipseLink 持久性属性妨碍

对我来说,解决方案是删除多余的 属性: <property name="eclipselink.ddl-generation" value="create-tables"/>

显然它与“javax.persistence.schema-generation.database.action”有冲突?

所以只需要:

<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"/>
          -->
        ...