我如何使用休眠生成迁移?

How i can generate migrations with hibernate?

我想通过使用休眠和 java 的代码优先方法生成我的数据库。我成功生成了数据库,但我错过了我的迁移文件。是否支持迁移,例如 .NEt 中的 EntityFrameworkCore、PHP 中的 Eloquent 或节点中的 Sequelize?

这是我生成数据库的class:

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;
    }


}

您可以使用 Liquibase or Flyway.

Both Flyway and Liquibase support all features that you need for professional database refactoring and versioning, so you will always know which version of the database schema you are dealing with and if it matches to the version of your software. Both tools are integrated with Maven or Gradle build scripts so that you can fully automate database refactoring.