GenerationTarget 遇到异常接受命令:通过 JDBC 语句执行 DDL 时出错
我是hibernate世界的新手,面对,
警告:GenerationTarget 遇到异常接受命令:通过 JDBC 语句执行 DDL 时出错org.hibernate.tool.schema.spi.CommandAcceptanceException:通过 JDBC 语句执行 DDL 时出错
当我在休眠 5.2.9 版本中运行我的独立程序时出现异常.但在 hibernate 4 版本中,我所有的代码都运行良好.我寻找了很多问题并解决了,但没有得到有效的答案.
<块引用>配置文件
hibernate.cfg.xml<休眠配置><会话工厂><property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property><property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property><property name="hibernate.connection.url">jdbc:mysql://localhost:3306/test</property><property name="hibernate.connection.username">root</property><property name="hibernate.connection.password">admin</property><property name="hibernate.connection.pool_size">20</property><property name="hibernate.show_sql">true</property><property name="hibernate.hbm2ddl.auto">创建</property><mapping class="com.test.hibernate14417.MyTable"></mapping></会话工厂></休眠配置>
<块引用>
Pom.xml
<?xml version="1.0" encoding="UTF-8"?><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><groupId>com.test</groupId><artifactId>Hibernate14417</artifactId><版本>1.0-SNAPSHOT</版本><包装>罐子</包装><存储库></存储库><依赖关系><依赖性><groupId>org.hibernate</groupId><artifactId>hibernate-core</artifactId><version>5.2.9.Final</version></依赖><依赖性><groupId>org.hibernate.javax.persistence</groupId><artifactId>hibernate-jpa-2.1-api</artifactId><version>1.0.0.Final</version></依赖><依赖性><groupId>org.hibernate</groupId><artifactId>hibernate-entitymanager</artifactId><version>4.3.1.Final</version></依赖><依赖性><groupId>net.sourceforge.jtds</groupId><artifactId>jtds</artifactId><版本>1.3.1</版本></依赖><依赖性><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId><版本>3.1.11</版本></依赖></依赖关系><属性><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding><maven.compiler.source>1.8</maven.compiler.source><maven.compiler.target>1.8</maven.compiler.target></属性></项目>
<块引用>
实用程序文件
包 com.test.hibernate14417;导入 org.hibernate.SessionFactory;导入 org.hibernate.boot.Metadata;导入 org.hibernate.boot.MetadataSources;导入 org.hibernate.boot.registry.StandardServiceRegistry;导入 org.hibernate.boot.registry.StandardServiceRegistryBuilder;导入 org.hibernate.service.ServiceRegistry;公共类 ExecuteUtil {私有静态最终SessionFactory SESSION_FACTORY=buildSessionFactory();私有静态 SessionFactory buildSessionFactory() {尝试 {ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().configure("hibernate.cfg.xml").build();元数据元数据 = new MetadataSources(serviceRegistry).buildMetadata();返回 metadata.getSessionFactoryBuilder().build();} 捕捉(可投掷的前){System.err.println("初始 SessionFactory 创建失败." + ex);抛出新的 ExceptionInInitializerError(ex);}}公共静态会话工厂 getSESSION_FACTORY() {返回会话工厂;}公共静态无效关机(){getSESSION_FACTORY().close();}}
<块引用>
实体文件
包 com.test.hibernate14417;导入 java.io.Serializable;导入 javax.persistence.Entity;导入 javax.persistence.GeneratedValue;导入 javax.persistence.GenerationType;导入 javax.persistence.Id;@实体公共类 MyTable 实现 Serializable {@ID@GeneratedValue(策略 = GenerationType.AUTO)私人 int id;私有字符串名称;公共 int getId() {返回标识;}公共无效setId(int id){这个.id = id;}公共字符串 getName() {返回名称;}公共无效集合名称(字符串名称){this.name = 名称;}}
<块引用>
主要方法
包 com.test.hibernate14417;导入 org.hibernate.Session;导入 org.hibernate.SessionFactory;公共类主要{公共静态无效主要(字符串[]参数){我的表 mt=新的我的表();mt.setName("男人");SessionFactory sessionFactory=ExecuteUtil.getSESSION_FACTORY();会话会话=sessionFactory.getCurrentSession();尝试 {session.getTransaction().begin();session.save(mt);session.getTransaction().commit();session.close();sessionFactory.close();} 捕捉(异常 e){System.out.println(e.getStackTrace());session.getTransaction().rollback();}}
<块引用>
控制台
cd D:NetbeansHibernate14417;"JAVA_HOME=C:\Program Files\Java\jdk1.8.0_121" cmd/c """C:\Program Files\NetBeans 8.2\java\maven\bin\mvn.bat" -Dexec.args="-classpath %classpath com.test.hibernate14417.Main" -Dexec.executable="C:\Program Files\Java\jdk1.8.0_121\bin\java.exe" -Dmaven.ext.class.path="C:\Program Files\NetBeans 8.2\java\maven-nblib\netbeans-eventspy.jar" -Dfile.encoding=UTF-8 org.codehaus.mojo:exec-maven-plugin:1.2.1:exec""运行 NetBeans Compile On Save 执行.跳过阶段执行,将使用依赖项目的输出目录(打开保存时编译)而不是它们的 jar 工件.正在扫描项目...------------------------------------------------------------------------构建 Hibernate14417 1.0-SNAPSHOT--------------------------------------------------------------------------- exec-maven-plugin:1.2.1:exec (default-cli) @ Hibernate14417 ---2017 年 4 月 14 日上午 10:41:51 org.hibernate.Version logVersion信息:HHH000412:休眠核心 {5.2.9.Final}2017 年 4 月 14 日上午 10:41:51 org.hibernate.cfg.Environment <clinit>信息:HHH000206:找不到 hibernate.properties2017 年 4 月 14 日上午 10:41:53 org.hibernate.boot.jaxb.internal.stax.LocalXmlResourceResolver resolveEntity警告:HHH90000012:已识别过时的休眠命名空间 http://hibernate.sourceforge.net/hibernate-configuration.请改用命名空间 http://www.hibernate.org/dtd/hibernate-configuration.可以随时删除对过时 DTD/XSD 命名空间的支持.2017 年 4 月 14 日上午 10:41:54 org.hibernate.annotations.common.reflection.java.JavaReflectionManager <clinit>信息:HCANN000001:Hibernate Commons Annotations {5.0.1.Final}2017 年 4 月 14 日上午 10:41:54 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl 配置警告:HHH10001002:使用 Hibernate 内置连接池(不用于生产!)2017 年 4 月 14 日上午 10:41:54 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator信息:HHH10001005:在 URL [jdbc:mysql://localhost:3306/test] 使用驱动程序 [com.mysql.jdbc.Driver]2017 年 4 月 14 日上午 10:41:54 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator信息:HHH10001001:连接属性:{用户=root,密码=****}2017 年 4 月 14 日上午 10:41:54 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator信息:HHH10001003:自动提交模式:假2017 年 4 月 14 日上午 10:41:54 org.hibernate.engine.jdbc.connections.internal.PooledConnections <init>信息:HHH000115:休眠连接池大小:20(min=1)2017 年 4 月 14 日上午 10:41:55 org.hibernate.dialect.Dialect <init>信息:HHH000400:使用方言:org.hibernate.dialect.MySQLDialect2017 年 4 月 14 日上午 10:41:55 org.hibernate.engine.jdbc.env.internal.LobCreatorBuilderImpl useContextualLobCreation信息:HHH000423:禁用上下文 LOB 创建,因为 JDBC 驱动程序报告 JDBC 版本 [3] 小于 4Hibernate:如果存在则删除表 hibernate_sequence2017 年 4 月 14 日上午 10:41:58 org.hibernate.resource.transaction.backend.jdbc.internal.DdlTransactionIsolatorNonJtaImpl getIsolatedConnection信息:HHH10001501:从 JdbcConnectionAccess [org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator$ConnectionProviderJdbcConnectionAccess@24111ef1] 获得的连接(非 JTA)DDL 执行未处于自动提交模式;连接本地事务"将被提交,连接将设置为自动提交模式.Hibernate:如果存在 MyTable,则删除表Hibernate:创建表 hibernate_sequence (next_val bigint) type=MyISAM2017 年 4 月 14 日上午 10:41:58 org.hibernate.resource.transaction.backend.jdbc.internal.DdlTransactionIsolatorNonJtaImpl getIsolatedConnection信息:HHH10001501:从 JdbcConnectionAccess [org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator$ConnectionProviderJdbcConnectionAccess@531f4093] 获得的连接(非 JTA)DDL 执行未处于自动提交模式;连接本地事务"将被提交,连接将设置为自动提交模式.2017 年 4 月 14 日上午 10:41:58 org.hibernate.tool.schema.internal.ExceptionHandlerLoggedImpl handleException警告:GenerationTarget 遇到异常接受命令:通过 JDBC 语句执行 DDL 时出错org.hibernate.tool.schema.spi.CommandAcceptanceException:通过 JDBC 语句执行 DDL 时出错在 org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase.accept(GenerationTargetToDatabase.java:67)在 org.hibernate.tool.schema.internal.SchemaCreatorImpl.applySqlString(SchemaCreatorImpl.java:440)在 org.hibernate.tool.schema.internal.SchemaCreatorImpl.applySqlStrings(SchemaCreatorImpl.java:424)在 org.hibernate.tool.schema.internal.SchemaCreatorImpl.createFromMetadata(SchemaCreatorImpl.java:315)在 org.hibernate.tool.schema.internal.SchemaCreatorImpl.performCreation(SchemaCreatorImpl.java:166)在 org.hibernate.tool.schema.internal.SchemaCreatorImpl.doCreation(SchemaCreatorImpl.java:135)在 org.hibernate.tool.schema.internal.SchemaCreatorImpl.doCreation(SchemaCreatorImpl.java:121)在 org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.performDatabaseAction(SchemaManagementToolCoordinator.java:155)在 org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.process(SchemaManagementToolCoordinator.java:72)在 org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:309)在 org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:445)在 com.test.hibernate14417.ExecuteUtil.buildSessionFactory(ExecuteUtil.java:29)在 com.test.hibernate14417.ExecuteUtil.<clinit>(ExecuteUtil.java:20)在 com.test.hibernate14417.Main.main(Main.java:21)原因:java.sql.SQLException:您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以在第 1 行的 'type=MyISAM' 附近使用正确的语法在 com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2926)在 com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1571)在 com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1666)在 com.mysql.jdbc.Connection.execSQL(Connection.java:2972)在 com.mysql.jdbc.Connection.execSQL(Connection.java:2902)在 com.mysql.jdbc.Statement.execute(Statement.java:529)在 org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase.accept(GenerationTargetToDatabase.java:54)... 13 更多Hibernate:插入 hibernate_sequence 值(1)2017 年 4 月 14 日上午 10:41:58 org.hibernate.tool.schema.internal.ExceptionHandlerLoggedImpl handleException警告:GenerationTarget 遇到异常接受命令:通过 JDBC 语句执行 DDL 时出错org.hibernate.tool.schema.spi.CommandAcceptanceException:通过 JDBC 语句执行 DDL 时出错在 org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase.accept(GenerationTargetToDatabase.java:67)在 org.hibernate.tool.schema.internal.SchemaCreatorImpl.applySqlString(SchemaCreatorImpl.java:440)在 org.hibernate.tool.schema.internal.SchemaCreatorImpl.applySqlStrings(SchemaCreatorImpl.java:424)在 org.hibernate.tool.schema.internal.SchemaCreatorImpl.createFromMetadata(SchemaCreatorImpl.java:315)在 org.hibernate.tool.schema.internal.SchemaCreatorImpl.performCreation(SchemaCreatorImpl.java:166)在 org.hibernate.tool.schema.internal.SchemaCreatorImpl.doCreation(SchemaCreatorImpl.java:135)在 org.hibernate.tool.schema.internal.SchemaCreatorImpl.doCreation(SchemaCreatorImpl.java:121)在 org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.performDatabaseAction(SchemaManagementToolCoordinator.java:155)在 org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.process(SchemaManagementToolCoordinator.java:72)在 org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:309)在 org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:445)在 com.test.hibernate14417.ExecuteUtil.buildSessionFactory(ExecuteUtil.java:29)在 com.test.hibernate14417.ExecuteUtil.<clinit>(ExecuteUtil.java:20)在 com.test.hibernate14417.Main.main(Main.java:21)引起:java.sql.SQLException:表'test.hibernate_sequence'不存在在 com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2926)在 com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1571)在 com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1666)在 com.mysql.jdbc.Connection.execSQL(Connection.java:2972)在 com.mysql.jdbc.Connection.execSQL(Connection.java:2902)在 com.mysql.jdbc.Statement.execute(Statement.java:529)在 org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase.accept(GenerationTargetToDatabase.java:54)... 13 更多Hibernate: 创建表 MyTable (id integer not null, name varchar(255), primary key (id)) type=MyISAM2017 年 4 月 14 日上午 10:41:58 org.hibernate.tool.schema.internal.ExceptionHandlerLoggedImpl handleException警告:GenerationTarget 遇到异常接受命令:通过 JDBC 语句执行 DDL 时出错org.hibernate.tool.schema.spi.CommandAcceptanceException:通过 JDBC 语句执行 DDL 时出错在 org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase.accept(GenerationTargetToDatabase.java:67)在 org.hibernate.tool.schema.internal.SchemaCreatorImpl.applySqlString(SchemaCreatorImpl.java:440)在 org.hibernate.tool.schema.internal.SchemaCreatorImpl.applySqlStrings(SchemaCreatorImpl.java:424)在 org.hibernate.tool.schema.internal.SchemaCreatorImpl.createFromMetadata(SchemaCreatorImpl.java:315)在 org.hibernate.tool.schema.internal.SchemaCreatorImpl.performCreation(SchemaCreatorImpl.java:166)在 org.hibernate.tool.schema.internal.SchemaCreatorImpl.doCreation(SchemaCreatorImpl.java:135)在 org.hibernate.tool.schema.internal.SchemaCreatorImpl.doCreation(SchemaCreatorImpl.java:121)在 org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.performDatabaseAction(SchemaManagementToolCoordinator.java:155)在 org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.process(SchemaManagementToolCoordinator.java:72)在 org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:309)在 org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:445)在 com.test.hibernate14417.ExecuteUtil.buildSessionFactory(ExecuteUtil.java:29)在 com.test.hibernate14417.ExecuteUtil.<clinit>(ExecuteUtil.java:20)在 com.test.hibernate14417.Main.main(Main.java:21)原因:java.sql.SQLException:您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以在第 1 行的 'type=MyISAM' 附近使用正确的语法在 com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2926)在 com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1571)在 com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1666)在 com.mysql.jdbc.Connection.execSQL(Connection.java:2972)在 com.mysql.jdbc.Connection.execSQL(Connection.java:2902)在 com.mysql.jdbc.Statement.execute(Statement.java:529)在 org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase.accept(GenerationTargetToDatabase.java:54)... 13 更多2017 年 4 月 14 日上午 10:41:58 org.hibernate.tool.schema.internal.SchemaCreatorImpl applyImportSources信息:HHH000476:执行导入脚本 'org.hibernate.tool.schema.internal.exec.ScriptSourceInputNonExistentImpl@7776ab'线程主"org.hibernate.HibernateException 中的异常:未配置 CurrentSessionContext!在 org.hibernate.internal.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:454)在 com.test.hibernate14417.Main.main(Main.java:23)
解决方案 您应该尝试不同的方言,例如org.hibernate.dialect.MySQL5Dialect
或 org.hibernate.dialect.MySQLMyISAMDialect
或 org.hibernate.dialect.MySQLInnoDBDialect
看看哪一个适合你.
总而言之,您当前的方言正在生成,type=MyISAM
而应该是,ENGINE=MyISAM
在创建表查询中.
mysql错误'TYPE=MyISAM'
您也应该阅读此内容,为什么需要配置数据源的SQL方言?
你的日志说这个查询被尝试执行,create table MyTable (id integer not null, name varchar(255), primary key (id)) type=MyISAM
所以你应该试试直接在 mysql 命令提示符上执行该查询,看看这是否适用于您的 MySQL 版本.
另外,请务必指定您的 MySQL 版本.
希望对你有帮助!!
I am a novice in hibernate world and facing,
WARN: GenerationTarget encountered exception accepting command : Error executing DDL via JDBC Statement
org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL via JDBC Statement
exception while I run my stand-alone programe in hibernate 5.2.9 version. But in hibernate 4 version all my code runs well. I looked for many questions and solve but not working answer i got.
Configuration file
hibernate.cfg.xml
<hibernate-configuration>
<session-factory>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/test</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">admin</property>
<property name="hibernate.connection.pool_size">20</property>
<property name="hibernate.show_sql">true</property>
<property name="hibernate.hbm2ddl.auto">create</property>
<mapping class="com.test.hibernate14417.MyTable"></mapping>
</session-factory>
</hibernate-configuration>
Pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.test</groupId>
<artifactId>Hibernate14417</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<repositories>
</repositories>
<dependencies>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.2.9.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.1-api</artifactId>
<version>1.0.0.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>4.3.1.Final</version>
</dependency>
<dependency>
<groupId>net.sourceforge.jtds</groupId>
<artifactId>jtds</artifactId>
<version>1.3.1</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>3.1.11</version>
</dependency>
</dependencies>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
</project>
Utility file
package com.test.hibernate14417;
import org.hibernate.SessionFactory;
import org.hibernate.boot.Metadata;
import org.hibernate.boot.MetadataSources;
import org.hibernate.boot.registry.StandardServiceRegistry;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.service.ServiceRegistry;
public class ExecuteUtil {
private static final SessionFactory SESSION_FACTORY=buildSessionFactory();
private static SessionFactory buildSessionFactory() {
try {
ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder()
.configure("hibernate.cfg.xml").build();
Metadata metadata = new MetadataSources(serviceRegistry).buildMetadata();
return metadata.getSessionFactoryBuilder().build();
} catch (Throwable ex) {
System.err.println("Initial SessionFactory creation failed." + ex);
throw new ExceptionInInitializerError(ex);
}
}
public static SessionFactory getSESSION_FACTORY() {
return SESSION_FACTORY;
}
public static void shutdown(){
getSESSION_FACTORY().close();
}
}
Entity file
package com.test.hibernate14417;
import java.io.Serializable;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
@Entity
public class MyTable implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private int id;
private String name;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
Main method
package com.test.hibernate14417;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
public class Main {
public static void main(String[] args) {
MyTable mt=new MyTable();
mt.setName("Man");
SessionFactory sessionFactory=ExecuteUtil.getSESSION_FACTORY();
Session session=sessionFactory.getCurrentSession();
try {
session.getTransaction().begin();
session.save(mt);
session.getTransaction().commit();
session.close();
sessionFactory.close();
} catch (Exception e) {
System.out.println(e.getStackTrace());
session.getTransaction().rollback();
}
}
Console
cd D:NetbeansHibernate14417; "JAVA_HOME=C:\Program Files\Java\jdk1.8.0_121" cmd /c """C:\Program Files\NetBeans 8.2\java\maven\bin\mvn.bat" -Dexec.args="-classpath %classpath com.test.hibernate14417.Main" -Dexec.executable="C:\Program Files\Java\jdk1.8.0_121\bin\java.exe" -Dmaven.ext.class.path="C:\Program Files\NetBeans 8.2\java\maven-nblib\netbeans-eventspy.jar" -Dfile.encoding=UTF-8 org.codehaus.mojo:exec-maven-plugin:1.2.1:exec""
Running NetBeans Compile On Save execution. Phase execution is skipped and output directories of dependency projects (with Compile on Save turned on) will be used instead of their jar artifacts.
Scanning for projects...
------------------------------------------------------------------------
Building Hibernate14417 1.0-SNAPSHOT
------------------------------------------------------------------------
--- exec-maven-plugin:1.2.1:exec (default-cli) @ Hibernate14417 ---
Apr 14, 2017 10:41:51 AM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {5.2.9.Final}
Apr 14, 2017 10:41:51 AM org.hibernate.cfg.Environment <clinit>
INFO: HHH000206: hibernate.properties not found
Apr 14, 2017 10:41:53 AM org.hibernate.boot.jaxb.internal.stax.LocalXmlResourceResolver resolveEntity
WARN: HHH90000012: Recognized obsolete hibernate namespace http://hibernate.sourceforge.net/hibernate-configuration. Use namespace http://www.hibernate.org/dtd/hibernate-configuration instead. Support for obsolete DTD/XSD namespaces may be removed at any time.
Apr 14, 2017 10:41:54 AM org.hibernate.annotations.common.reflection.java.JavaReflectionManager <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
Apr 14, 2017 10:41:54 AM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
WARN: HHH10001002: Using Hibernate built-in connection pool (not for production use!)
Apr 14, 2017 10:41:54 AM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001005: using driver [com.mysql.jdbc.Driver] at URL [jdbc:mysql://localhost:3306/test]
Apr 14, 2017 10:41:54 AM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001001: Connection properties: {user=root, password=****}
Apr 14, 2017 10:41:54 AM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001003: Autocommit mode: false
Apr 14, 2017 10:41:54 AM org.hibernate.engine.jdbc.connections.internal.PooledConnections <init>
INFO: HHH000115: Hibernate connection pool size: 20 (min=1)
Apr 14, 2017 10:41:55 AM org.hibernate.dialect.Dialect <init>
INFO: HHH000400: Using dialect: org.hibernate.dialect.MySQLDialect
Apr 14, 2017 10:41:55 AM org.hibernate.engine.jdbc.env.internal.LobCreatorBuilderImpl useContextualLobCreation
INFO: HHH000423: Disabling contextual LOB creation as JDBC driver reported JDBC version [3] less than 4
Hibernate: drop table if exists hibernate_sequence
Apr 14, 2017 10:41:58 AM org.hibernate.resource.transaction.backend.jdbc.internal.DdlTransactionIsolatorNonJtaImpl getIsolatedConnection
INFO: HHH10001501: Connection obtained from JdbcConnectionAccess [org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator$ConnectionProviderJdbcConnectionAccess@24111ef1] for (non-JTA) DDL execution was not in auto-commit mode; the Connection 'local transaction' will be committed and the Connection will be set into auto-commit mode.
Hibernate: drop table if exists MyTable
Hibernate: create table hibernate_sequence (next_val bigint) type=MyISAM
Apr 14, 2017 10:41:58 AM org.hibernate.resource.transaction.backend.jdbc.internal.DdlTransactionIsolatorNonJtaImpl getIsolatedConnection
INFO: HHH10001501: Connection obtained from JdbcConnectionAccess [org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator$ConnectionProviderJdbcConnectionAccess@531f4093] for (non-JTA) DDL execution was not in auto-commit mode; the Connection 'local transaction' will be committed and the Connection will be set into auto-commit mode.
Apr 14, 2017 10:41:58 AM org.hibernate.tool.schema.internal.ExceptionHandlerLoggedImpl handleException
WARN: GenerationTarget encountered exception accepting command : Error executing DDL via JDBC Statement
org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL via JDBC Statement
at org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase.accept(GenerationTargetToDatabase.java:67)
at org.hibernate.tool.schema.internal.SchemaCreatorImpl.applySqlString(SchemaCreatorImpl.java:440)
at org.hibernate.tool.schema.internal.SchemaCreatorImpl.applySqlStrings(SchemaCreatorImpl.java:424)
at org.hibernate.tool.schema.internal.SchemaCreatorImpl.createFromMetadata(SchemaCreatorImpl.java:315)
at org.hibernate.tool.schema.internal.SchemaCreatorImpl.performCreation(SchemaCreatorImpl.java:166)
at org.hibernate.tool.schema.internal.SchemaCreatorImpl.doCreation(SchemaCreatorImpl.java:135)
at org.hibernate.tool.schema.internal.SchemaCreatorImpl.doCreation(SchemaCreatorImpl.java:121)
at org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.performDatabaseAction(SchemaManagementToolCoordinator.java:155)
at org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.process(SchemaManagementToolCoordinator.java:72)
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:309)
at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:445)
at com.test.hibernate14417.ExecuteUtil.buildSessionFactory(ExecuteUtil.java:29)
at com.test.hibernate14417.ExecuteUtil.<clinit>(ExecuteUtil.java:20)
at com.test.hibernate14417.Main.main(Main.java:21)
Caused by: java.sql.SQLException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'type=MyISAM' at line 1
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2926)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1571)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1666)
at com.mysql.jdbc.Connection.execSQL(Connection.java:2972)
at com.mysql.jdbc.Connection.execSQL(Connection.java:2902)
at com.mysql.jdbc.Statement.execute(Statement.java:529)
at org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase.accept(GenerationTargetToDatabase.java:54)
... 13 more
Hibernate: insert into hibernate_sequence values ( 1 )
Apr 14, 2017 10:41:58 AM org.hibernate.tool.schema.internal.ExceptionHandlerLoggedImpl handleException
WARN: GenerationTarget encountered exception accepting command : Error executing DDL via JDBC Statement
org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL via JDBC Statement
at org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase.accept(GenerationTargetToDatabase.java:67)
at org.hibernate.tool.schema.internal.SchemaCreatorImpl.applySqlString(SchemaCreatorImpl.java:440)
at org.hibernate.tool.schema.internal.SchemaCreatorImpl.applySqlStrings(SchemaCreatorImpl.java:424)
at org.hibernate.tool.schema.internal.SchemaCreatorImpl.createFromMetadata(SchemaCreatorImpl.java:315)
at org.hibernate.tool.schema.internal.SchemaCreatorImpl.performCreation(SchemaCreatorImpl.java:166)
at org.hibernate.tool.schema.internal.SchemaCreatorImpl.doCreation(SchemaCreatorImpl.java:135)
at org.hibernate.tool.schema.internal.SchemaCreatorImpl.doCreation(SchemaCreatorImpl.java:121)
at org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.performDatabaseAction(SchemaManagementToolCoordinator.java:155)
at org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.process(SchemaManagementToolCoordinator.java:72)
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:309)
at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:445)
at com.test.hibernate14417.ExecuteUtil.buildSessionFactory(ExecuteUtil.java:29)
at com.test.hibernate14417.ExecuteUtil.<clinit>(ExecuteUtil.java:20)
at com.test.hibernate14417.Main.main(Main.java:21)
Caused by: java.sql.SQLException: Table 'test.hibernate_sequence' doesn't exist
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2926)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1571)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1666)
at com.mysql.jdbc.Connection.execSQL(Connection.java:2972)
at com.mysql.jdbc.Connection.execSQL(Connection.java:2902)
at com.mysql.jdbc.Statement.execute(Statement.java:529)
at org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase.accept(GenerationTargetToDatabase.java:54)
... 13 more
Hibernate: create table MyTable (id integer not null, name varchar(255), primary key (id)) type=MyISAM
Apr 14, 2017 10:41:58 AM org.hibernate.tool.schema.internal.ExceptionHandlerLoggedImpl handleException
WARN: GenerationTarget encountered exception accepting command : Error executing DDL via JDBC Statement
org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL via JDBC Statement
at org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase.accept(GenerationTargetToDatabase.java:67)
at org.hibernate.tool.schema.internal.SchemaCreatorImpl.applySqlString(SchemaCreatorImpl.java:440)
at org.hibernate.tool.schema.internal.SchemaCreatorImpl.applySqlStrings(SchemaCreatorImpl.java:424)
at org.hibernate.tool.schema.internal.SchemaCreatorImpl.createFromMetadata(SchemaCreatorImpl.java:315)
at org.hibernate.tool.schema.internal.SchemaCreatorImpl.performCreation(SchemaCreatorImpl.java:166)
at org.hibernate.tool.schema.internal.SchemaCreatorImpl.doCreation(SchemaCreatorImpl.java:135)
at org.hibernate.tool.schema.internal.SchemaCreatorImpl.doCreation(SchemaCreatorImpl.java:121)
at org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.performDatabaseAction(SchemaManagementToolCoordinator.java:155)
at org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.process(SchemaManagementToolCoordinator.java:72)
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:309)
at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:445)
at com.test.hibernate14417.ExecuteUtil.buildSessionFactory(ExecuteUtil.java:29)
at com.test.hibernate14417.ExecuteUtil.<clinit>(ExecuteUtil.java:20)
at com.test.hibernate14417.Main.main(Main.java:21)
Caused by: java.sql.SQLException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'type=MyISAM' at line 1
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2926)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1571)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1666)
at com.mysql.jdbc.Connection.execSQL(Connection.java:2972)
at com.mysql.jdbc.Connection.execSQL(Connection.java:2902)
at com.mysql.jdbc.Statement.execute(Statement.java:529)
at org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase.accept(GenerationTargetToDatabase.java:54)
... 13 more
Apr 14, 2017 10:41:58 AM org.hibernate.tool.schema.internal.SchemaCreatorImpl applyImportSources
INFO: HHH000476: Executing import script 'org.hibernate.tool.schema.internal.exec.ScriptSourceInputNonExistentImpl@7776ab'
Exception in thread "main" org.hibernate.HibernateException: No CurrentSessionContext configured!
at org.hibernate.internal.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:454)
at com.test.hibernate14417.Main.main(Main.java:23)
解决方案
You should try a different dialects likeorg.hibernate.dialect.MySQL5Dialect
OR org.hibernate.dialect.MySQLMyISAMDialect
OR org.hibernate.dialect.MySQLInnoDBDialect
to see which one works for you.
All in all , your current dialect is generating , type=MyISAM
while it should be , ENGINE=MyISAM
in create table query.
mysql error 'TYPE=MyISAM'
You should read this too , Why do I need to configure the SQL dialect of a data source?
Your logs say that this query was tried to be executed , create table MyTable (id integer not null, name varchar(255), primary key (id)) type=MyISAM
so you should try to execute that query directly on mysql command prompt to see if that works for your MySQL version.
Also, in question do specify your MySQL version too.
Hope it helps !!
相关文章