org.hibernate.tool.schema.spi.SchemaManagementException Unable to execute schema management to 异常的解决

org.hibernate.tool.schema.spi.SchemaManagementException Unable to execute schema management to JDBC target 异常的解决

今天写了个简单的多对多关系,测试运行后,报了一个异常,多方检查配置文件,并没什么明显的错误,很是苦恼。

org.hibernate.tool.schema.spi.SchemaManagementException: Unable to execute schema management to JDBC target [create table sys_role (role_id bigint not null auto_increment, role_name varchar(255), role_memo varchar(255), primary key (role_id)) type=InnoDB]
    	at org.hibernate.tool.schema.internal.TargetDatabaseImpl.accept(TargetDatabaseImpl.java:59)
    	at org.hibernate.tool.schema.internal.SchemaMigratorImpl.applySqlString(SchemaMigratorImpl.java:431)
    	at org.hibernate.tool.schema.internal.SchemaMigratorImpl.applySqlStrings(SchemaMigratorImpl.java:420)
    	at org.hibernate.tool.schema.internal.SchemaMigratorImpl.createTable(SchemaMigratorImpl.java:236)
    	at org.hibernate.tool.schema.internal.SchemaMigratorImpl.doMigrationToTargets(SchemaMigratorImpl.java:167)
    	at org.hibernate.tool.schema.internal.SchemaMigratorImpl.doMigration(SchemaMigratorImpl.java:60)
    	at org.hibernate.tool.hbm2ddl.SchemaUpdate.execute(SchemaUpdate.java:133)
    	at org.hibernate.tool.hbm2ddl.SchemaUpdate.execute(SchemaUpdate.java:101)
    	at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:470)
    	at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:444)
    	at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:708)
    	at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:724)
    	at cn.cigar.many2many.Demo.function(Demo.java:21)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    	at java.lang.reflect.Method.invoke(Unknown Source)
    	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
    	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
    	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
    	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
    	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
    	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    	at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    	at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
    	at org.junit.runner.JUnitCore.run(JUnitCore.java:115)
    	at org.junit.vintage.engine.execution.RunnerExecutor.execute(RunnerExecutor.java:39)
    	at java.util.stream.ForEachOps$ForEachOp$OfRef.accept(Unknown Source)
    	at java.util.stream.ReferencePipeline$3$1.accept(Unknown Source)
    	at java.util.Iterator.forEachRemaining(Unknown Source)
    	at java.util.Spliterators$IteratorSpliterator.forEachRemaining(Unknown Source)
    	at java.util.stream.AbstractPipeline.copyInto(Unknown Source)
    	at java.util.stream.AbstractPipeline.wrapAndCopyInto(Unknown Source)
    	at java.util.stream.ForEachOps$ForEachOp.evaluateSequential(Unknown Source)
    	at java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(Unknown Source)
    	at java.util.stream.AbstractPipeline.evaluate(Unknown Source)
    	at java.util.stream.ReferencePipeline.forEach(Unknown Source)
    	at org.junit.vintage.engine.VintageTestEngine.executeAllChildren(VintageTestEngine.java:79)
    	at org.junit.vintage.engine.VintageTestEngine.execute(VintageTestEngine.java:70)
    	at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:170)
    	at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:154)
    	at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:90)
    	at org.eclipse.jdt.internal.junit5.runner.JUnit5TestReference.run(JUnit5TestReference.java:86)
    	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:538)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:760)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:460)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:206)
    Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: 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=InnoDB' at line 1
    	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    	at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    	at java.lang.reflect.Constructor.newInstance(Unknown Source)
    	at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
    	at com.mysql.jdbc.Util.getInstance(Util.java:381)
    	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1030)
    	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)
    	at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3515)
    	at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3447)
    	at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1951)
    	at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2101)
    	at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2548)
    	at com.mysql.jdbc.StatementImpl.executeUpdate(StatementImpl.java:1605)
    	at com.mysql.jdbc.StatementImpl.executeUpdate(StatementImpl.java:1524)
    	at org.hibernate.tool.schema.internal.TargetDatabaseImpl.accept(TargetDatabaseImpl.java:56)
    	... 53 more

后来多方百度,有说是可能和数据库方言版本有关,尝试着修改了数据库方言的版本,再运行,居然测试成功。

原来的方言配置:

<property name="hibernate.dialect">org.hibernate.dialect.MySQLInnoDBDialect</property>

修改后的方言配置:

<property name="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect</property>

修改后就大功告成。
在这里插入图片描述

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值