【发布时间】:2017-11-27 23:48:04
【问题描述】:
我想使用 Hibernate/HBM2DDL 模式生成作为使用 Liquibase 或 Flyway 等工具管理我的应用程序的 SQL 模式的起点。为了解决这个问题,我需要在我的项目中运行一个小实用程序,我可以运行它来打印自动生成的架构。
对于旧版本或 Hibernate,这相对简单。像下面这样的东西会起作用:
EntityManagerFactory emf = null; // TODO: create your EMF the usual way.
Class<? extends Dialect> hibernateDialectType = null; // TODO: e.g. HSQLDialect.class.
Configuration hibernateConfig = new Configuration();
hibernateConfig.setProperty(Environment.DIALECT, hibernateDialectType.getName());
for (EntityType<?> entityType : emf.getMetamodel().getEntities()) {
hibernateConfig.addAnnotatedClass(entityType.getJavaType());
}
SchemaExport schemaExporter = new SchemaExport(hibernateConfig);
schemaExporter.setFormat(true);
schemaExporter.setDelimiter(";");
schemaExporter.create(Target.SCRIPT);
但至少从 Hibernate 5.2 开始,SchemaExport 实用程序不能从 Hibernate Configuration 实例构建。
那么现在怎么能做到呢?
【问题讨论】:
标签: java hibernate jpa hbm2ddl