我想用MySQL構建一個使用Hibernate JPA的簡單應用程序,但每當我嘗試將其部署到Wildfly時,我都會收到「缺少表」錯誤。JPA/Hibernate:缺少表錯誤
我的持久化類看起來是這樣的:
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安裝有什麼問題?
這樣做的竅門,謝謝! – Znorg