将Hibernate升级到5.1.0后如何导出模式? [英] How do I export schema after upgrading Hibernate to 5.1.0?

查看:129
本文介绍了将Hibernate升级到5.1.0后如何导出模式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近将Hibernate从5.0更新到5.1,并且 SchemaExport API已更改。迁移文档提到了此更改,但不解释如何使用较新的API。此外,我还没有找到任何其他支持示例来修复重大更改。

I've recently updated Hibernate from 5.0 to 5.1 and the SchemaExport API has changed. The migration docs mention this change, but do not explain how to use the newer API. Moreover, I have not been able to find any other supporting sample to fix the breaking change.

推荐答案

我偶然发现了这段代码diff这帮助我解决了API中的差异: https://gitlab.nuiton.org/nuiton / topia / commit / 0c57f073ad879a981e9fa3315f0e04669a57858b

I stumbled upon this code diff that helped me solve the differences in the API: https://gitlab.nuiton.org/nuiton/topia/commit/0c57f073ad879a981e9fa3315f0e04669a57858b

这里是我的代码,它将任何带有@Entity标注的类的模式导出到输出窗口。
$ b

Here's my code which exports schema for any Class marked with @Entity annotation to the output window.

  static void getDDL(String packageName, String propertiesFile) throws IOException {

    MetadataSources metadata = new MetadataSources(
        new StandardServiceRegistryBuilder()
            .loadProperties(propertiesFile)
            .build());

    new Reflections(packageName)
        .getTypesAnnotatedWith(Entity.class)
        .forEach(metadata::addAnnotatedClass);

    //STDOUT will export to output window, but other `TargetType` values are available to export to file or to the db.
    EnumSet<TargetType> targetTypes = EnumSet.of(TargetType.STDOUT);

    SchemaExport export = new SchemaExport();

    export.setDelimiter(";");
    export.setFormat(true);

    export.createOnly(targetTypes, metadata.buildMetadata());
}

这篇关于将Hibernate升级到5.1.0后如何导出模式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆