使用在特性和Derby配置中配置jpa-2.2的开放自由版本21.0.12:
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脚本似乎没有加载。DB表似乎是被创建的,但它们是空的;我用INSERT(s)填充它们的脚本似乎没有运行,甚至在打开Open跟踪时也没有出现明显的错误。
发布于 2022-03-30 19:58:26
删除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"/>
-->
...https://stackoverflow.com/questions/71683422
复制相似问题