hibernate中使用schemaExport生成数据表报错解决方法
Posted baorant
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了hibernate中使用schemaExport生成数据表报错解决方法相关的知识,希望对你有一定的参考价值。
【解决方法】
1.hibernate中使用schemaexport生成数据表,很多教材是教你这么写的:
- SchemaExport schemaExport = new SchemaExport(new Configuration().configure());
- schemaExport.create(true, true);
因为我们现在基本都是使用hibernate 5.x,所以当你这么写的时候,IDE会提醒你这种方法已经不推荐使用了。
2.解决方法:将以上代码改成以下代码:
- ServiceRegistry serviceRegistry = (ServiceRegistry) new StandardServiceRegistryBuilder().configure().build();
- MetadataImplementor metadataImplementor = (MetadataImplementor) new MetadataSources(serviceRegistry).buildMetadata();
- SchemaExport export = new SchemaExport(serviceRegistry, metadataImplementor);
- export.create(true, true);
重新运行,(如果你的hibernate和数据库驱动的jar已经正确导入),应该是OK了。
以上是关于hibernate中使用schemaExport生成数据表报错解决方法的主要内容,如果未能解决你的问题,请参考以下文章
Hibernate SchemaExport 无法首先创建架构
hibernate笔记--通过SchemaExport生成数据库表
hibernate4.2.2使用schemaExport生成数据表报错,junit提示:SQLNestedException: Cannot create PoolableConnectionFact
在 JUnit/Spring 测试期间触发 Hibernate 的 SchemaExport.execute (hbm2ddl.auto) 的原因是啥?