错误使用JPA持久性架构生成时未指定脚本

时间:2015-07-27 22:59:23

标签: jpa database-schema persistence.xml

在Wildly 8.2.0.Final上运行。尝试从脚本生成数据库架构时出现以下错误。

引起:javax.persistence.PersistenceException:模式生成配置表明包含CREATE脚本,但未指定脚本

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1"


 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_1.xsd">
   <persistence-unit name="com.mycompany_mavenFlowChartDB5_war_1.0-SNAPSHOTPU" transaction-type="JTA">
    <jta-data-source>java:jboss/datasources/postgresql</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=""/>
      <property name="javax.persistence.schema-generation.create-source" value="script"/>
      <property name="javax.persistence.schema-generation.drop-source" value="script"/>
      <property name="javax.persistence.schema-generation.scripts.action" value="none"/>
      <property name="javax.persistence.schema-generation.scripts.drop-target" value="META-INF/drop-script.sql"/>
      <property name="javax.persistence.schema-generation.scripts.create-target" value="META-INF/create-script.sql"/>
    </properties>
  </persistence-unit>
</persistence>

创建脚本所在的位置: /src/main/resources/META-INF/create-script.sql

提前致谢!

1 个答案:

答案 0 :(得分:2)

Wildfly持久性架构生成器gui为drop创建不正确的属性名称并创建目标。

正确的属性名称是

<property name="javax.persistence.schema-generation.drop-script-source" value="META-INF/drop-script.sql"/>
        <property name="javax.persistence.schema-generation.create-script-source" value="META-INF/create-script.sql"/>

将create-script更改为create-script-source,将drop-script更改为drop-script-source

来源:https://github.com/hantsy/ee7-sandbox