ddl语句_如何使用Hibernate从Play生成DDL脚本! 框架项目

ddl语句

ddl语句

Screen-Shot-2014-10-15-at-23.34.25
好的,因此您一直在使用hibernate属性名称=“ hibernate.hbm2ddl.auto ” value =“更新”来不断更新数据库架构,但是现在您需要一个完整的DDL脚本吗?

从全局类onStart中使用此方法可导出DDL脚本。 只需为其提供实体的包名称(带有路径)以及文件名即可:

public void onStart(Application app) {
        exportDatabaseSchema("models", "create_tables.sql");
    }

    public void exportDatabaseSchema(String packageName, String scriptFilename) {

        final Configuration configuration = new Configuration();
        final Reflections reflections = new Reflections(packageName);
        final Set<Class<?>> classes = reflections.getTypesAnnotatedWith(Entity.class);
        // iterate all Entity classes in the package indicated by the name
        for (final Class<?> clazz : classes) {
            configuration.addAnnotatedClass(clazz);
        }
        configuration.setProperty("hibernate.dialect", "org.hibernate.dialect.PostgreSQL9Dialect");

        SchemaExport schema = new SchemaExport(configuration);
        schema.setOutputFile(scriptFilename);
        schema.setDelimiter(";");
        schema.execute(Target.SCRIPT, SchemaExport.Type.CREATE );  // just export the create statements in the script
    }

这就对了!

感谢@MonCalamari在这里回答我有关Stackoverflow的问题

翻译自: https://www.javacodegeeks.com/2014/10/how-to-use-hibernate-to-generate-a-ddl-script-from-your-play-framework-project.html

ddl语句

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值