【问题标题】:JPA persistence.xml not dropping all schema tablesJPA persistence.xml 不删除所有模式表
【发布时间】:2015-03-30 20:26:25
【问题描述】:

当我部署到 Wildfly 时,我希望我的所有数据库表都将被删除并重新创建。但是我的数据库中仍然存在一些旧表(旧 Java 实体)。

这是我的persistence.xml 文件:

<?xml version="1.0" encoding="UTF-8"?>
<persistence 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"
    version="2.1">

    <persistence-unit name="gestalPU">
        <provider>org.hibernate.ejb.HibernatePersistence</provider>
        <jta-data-source>java:jboss/datasources/MySQLDS</jta-data-source>

        <properties>

            <property name="javax.persistence.schema-generation.database.action"
                value="drop-and-create" />
            <property name="javax.persistence.schema-generation.create-source"
                value="metadata" />
            <property name="javax.persistence.schema-generation.drop-source"
                value="metadata" />
            <property name="javax.persistence.sql-load-script-source"
                value="insert.sql" />
            <property name="javax.persistence.schema-generation.create-database-schemas" value="true"/>
        </properties>
    </persistence-unit>    
</persistence>        

【问题讨论】:

  • 是一些当前 JPA 实体的“旧表”吗?

标签: hibernate jpa wildfly


【解决方案1】:

drop-and-create 只删除与当前实体相关的表,它不会清除整个架构。

因此,例如,如果您重命名了一个实体,则与旧实体名称对应的表将保留在数据库中。

【讨论】:

  • 在创建新表之前如何自动删除所有表?
猜你喜欢
  • 2013-02-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-10-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多