【问题标题】:How i can generate migrations with hibernate?我如何使用休眠生成迁移?
【发布时间】:2019-05-18 01:06:26
【问题描述】:

我想通过代码优先方法使用 hibernate 和 java 生成我的数据库。我已成功生成数据库,但我错过了我的迁移文件。对 .NET 中的 EntityFrameworkCore、PHP 中的 Eloquent 或节点中的 Sequelize 等迁移有休眠支持吗?

这是我生成数据库的类:

public class CreateDataBase {
    public static void main(String[] args) {
      Configuration conf = new Configuration();
      conf.configure();

      SchemaExport se = new SchemaExport(conf);
      se.create(true,  true);  
    }
}

这是我的架构:

package Infra.HibernateConfiguration;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;

@Entity 
public class Bank {
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private int id; 

    @Column()
    private String code;

    @Column()
    private String name;

    public int getId() {
        return id;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }


}

【问题讨论】:

    标签: java hibernate migration code-first


    【解决方案1】:

    您可以使用LiquibaseFlyway

    Flyway 和 Liquibase 都支持您需要的所有功能 专业的数据库重构和版本控制,让您永远 知道您正在处理的数据库模式的版本以及是否 它与您的软件版本相匹配。两种工具都集成在一起 使用 Maven 或 Gradle 构建脚本,以便您可以完全自动化数据库重构。

    【讨论】:

      猜你喜欢
      • 2014-03-11
      • 2015-12-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-12-23
      • 2013-03-11
      • 2011-12-26
      • 1970-01-01
      相关资源
      最近更新 更多