使用 Open Liberty 版本 21.0.0.12 并jpa-2.2在特性和 Derby DS 配置之間進行配置:
服務器.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 定義為:
持久性.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 跟蹤也沒有出現明顯的錯誤。
uj5u.com熱心網友回復:
洗掉礙事的 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://www.uj5u.com/qiye/455305.html
標籤:jpa 日食链接 websphere-自由 开放自由
