已解决 问题出在 JBoss Standalone.xml 文件中。胖手指了数据库名称 - 然后它找不到表。对于看到此错误的其他任何人(因为我发现了很多未解决的问题),请查看您的驱动程序和数据库定义。
我正在尝试通过 Eclipse 中的 Hibernate 加载填充的 MySQL 数据库。我知道我已经成功连接了数据库,因为我可以通过 Eclipse 对其进行 ping 操作。但是,当我发布时,它告诉我找不到该表。我不确定我错过了什么。
请参见下面的 persistence.xml 文件:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" 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">
<persistence-unit name="TEST">
<jta-data-source>java:jboss/datasources/CSER-DS</jta-data-source>
<class>org.package.Nicknames</class>
<properties>
<property name="hibernate.show_sql" value="true"/>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect"/>
<property name="hibernate.connection.username" value="db_user"/>
<property name="hibernate.connection.password" value=""/>
<property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/>
<property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/cser_db"/>
<property name="hibernate.hbm2ddl.auto" value="update" />
<property name="hibernate.generate_statistics" value="true" />
<property name="hibernate.archive.autodetection" value="class"/>
</properties>
</persistence-unit>
</persistence>
实体文件:
package org.package.Nicknames;
import java.io.Serializable;
import java.lang.String;
import javax.persistence.*;
@Entity
@Table(name="Nicknames")
public class Nicknames implements Serializable {
@Id
@Column(name = "longName", unique = true, nullable = false, length = 50)
private String longName;
@Column(name = "shortName", nullable = false, length = 25)
private String shortName;
private static final long serialVersionUID = 1L;
public String getName() {
return longName;
}
public void setName(String longName) {
this.longName = longName;
}
public String getShortName() {
return shortName;
}
public void setShortName(String shortName) {
this.shortName = shortName;
}
public static long getSerialversionuid() {
return serialVersionUID;
}
}
我遇到的错误是:
16:16:40,483 INFO [org.hibernate.service.jdbc.connections.internal.ConnectionProviderInitiator] (MSC service thread 1-5) HHH000130: Instantiating explicit connection provider: org.hibernate.ejb.connection.InjectedDataSourceConnectionProvider
16:16:40,674 INFO [org.hibernate.dialect.Dialect] (MSC service thread 1-5) HHH000400: Using dialect: org.hibernate.dialect.MySQL5InnoDBDialect
16:16:40,680 INFO [org.hibernate.engine.jdbc.internal.LobCreatorBuilder] (MSC service thread 1-5) HHH000423: Disabling contextual LOB creation as JDBC driver reported JDBC version [3] less than 4
16:16:40,689 INFO [org.hibernate.engine.transaction.internal.TransactionFactoryInitiator] (MSC service thread 1-5) HHH000268: Transaction strategy: org.hibernate.engine.transaction.internal.jta.CMTTransactionFactory
16:16:40,693 INFO [org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory] (MSC service thread 1-5) HHH000397: Using ASTQueryTranslatorFactory
16:16:40,721 INFO [org.hibernate.validator.util.Version] (MSC service thread 1-5) Hibernate Validator 4.2.0.Final
16:16:40,931 INFO [org.hibernate.tool.hbm2ddl.SchemaUpdate] (MSC service thread 1-5) HHH000228: Running hbm2ddl schema update
16:16:40,932 INFO [org.hibernate.tool.hbm2ddl.SchemaUpdate] (MSC service thread 1-5) HHH000102: Fetching database metadata
16:16:40,936 INFO [org.hibernate.tool.hbm2ddl.SchemaUpdate] (MSC service thread 1-5) HHH000396: Updating schema
16:16:40,941 INFO [java.sql.DatabaseMetaData] (MSC service thread 1-5) HHH000262: Table not found: Nicknames
16:16:40,942 INFO [java.sql.DatabaseMetaData] (MSC service thread 1-5) HHH000262: Table not found: Nicknames
16:16:40,947 ERROR [org.hibernate.tool.hbm2ddl.SchemaUpdate] (MSC service thread 1-5) HHH000388: Unsuccessful: create table Nicknames (longName varchar(50) not null unique, shortName varchar(25) not null, primary key (longName)) ENGINE=InnoDB
16:16:40,948 ERROR [org.hibernate.tool.hbm2ddl.SchemaUpdate] (MSC service thread 1-5) Syntax error in SQL statement "CREATE TABLE NICKNAMES (LONGNAME VARCHAR(50) NOT NULL UNIQUE, SHORTNAME VARCHAR(25) NOT NULL, PRIMARY KEY (LONGNAME)) ENGINE=[*]INNODB "; expected "identifier"; SQL statement:
create table Nicknames (longName varchar(50) not null unique, shortName varchar(25) not null, primary key (longName)) ENGINE=InnoDB [42001-161]
16:16:40,949 INFO [org.hibernate.tool.hbm2ddl.SchemaUpdate] (MSC service thread 1-5) HHH000232: Schema update complete
16:16:40,971 INFO [org.jboss.weld.deployer] (MSC service thread 1-1) JBAS016008: Starting weld service for deployment TEST.war
16:16:41,578 INFO [javax.enterprise.resource.webcontainer.jsf.config] (MSC service thread 1-3) Initializing Mojarra 2.1.7-jbossorg-1 (20120227-1401) for context '/TEST'
16:16:42,445 INFO [org.jboss.web] (MSC service thread 1-3) JBAS018210: Registering web context: /TEST
16:16:42,506 INFO [org.jboss.as.server] (DeploymentScanner-threads - 2) JBAS018559: Deployed "TEST.war"