【问题标题】:JPA/Hibernate: Missing table errorJPA/Hibernate:缺少表错误
【发布时间】:2016-04-22 20:16:23
【问题描述】:

我正在尝试使用带有 MySQL 的 Hibernate JPA 构建一个简单的应用程序,但每当我尝试将其部署到 Wildfly 时,我都会收到“缺少表”错误。

我的持久类如下所示:

package com.example;

@Entity @Table
public class FooBar {
    //...
}

这是我的 persistence.xml:

<persistence xmlns="http://java.sun.com/xml/ns/persistence"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
    version="2.0">
    <persistence-unit name="ExampleJPA">
        <provider>org.hibernate.ejb.HibernatePersistence</provider>

        <class>com.example.FooBar</class>

        <properties>
            <!-- Configuring JDBC properties -->
            <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/mydatabase" />
            <property name="javax.persistence.jdbc.user" value="(my user)" />
            <property name="javax.persistence.jdbc.password" value="(my password)" />
            <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" />

            <!-- Hibernate properties -->
            <property name="hibernate.show_sql" value="true" />
            <property name="hibernate.format_sql" value="true" />
            <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect" />
            <property name="hibernate.hbm2ddl.auto" value="validate" />

            <!-- Configuring Connection Pool -->
            <property name="hibernate.c3p0.min_size" value="5" />
            <property name="hibernate.c3p0.max_size" value="20" />
            <property name="hibernate.c3p0.timeout" value="500" />
            <property name="hibernate.c3p0.max_statements" value="50" />
            <property name="hibernate.c3p0.idle_test_period" value="2000" />

        </properties>
    </persistence-unit>
</persistence>

这是我在部署到 Wildfly 8 服务器时收到的消息:

org.jboss.msc.service.StartException in service jboss.persistenceunit.\"ExampleJPA.war#ExampleJPA\": org.hibernate.HibernateException: Missing table: FooBar 引起:org.hibernate.HibernateException:缺少表:FooBar

我在数据库中有一个名为 FooBar 的表。我可以使用在 persistence.xml 中定义的相同 url、用户和密码直接通过 JDBC 访问它。我的 JPA 设置有什么问题?

【问题讨论】:

    标签: mysql hibernate jpa


    【解决方案1】:

    架构中不存在您的表,因此“validate”的hibernate.hbm2ddl.auto 值失败。创建表或将hibernate.hbm2ddl.auto 值更改为“create”或“update”。

    【讨论】:

      猜你喜欢
      • 2015-05-02
      • 2021-08-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-09-19
      • 1970-01-01
      • 2016-09-17
      • 2012-04-07
      相关资源
      最近更新 更多