本文介绍了用java飞行迁移的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我学习了flywaydb迁移,java使用JDBC连接,并且还通过SpringTemplate支持spring,但是flyway不能与DAO一起使用。

I learnt flywaydb migration with java works with JDBC connection and also spring support through SpringTemplate, but flyway doesn't work with DAOs.

用于更多的表/实体关系,它使用DAO而不是sql进行迁移变得更容易。

for tables/entities with more relationships,it makes life much easier to do migration with DAO's rather than sql.

是否有解决方案或解决方法来解决这个问题?

is there a solution or work-around to deal with this ?

推荐答案

首先,Flyway有自己的交易管理系统,不使用Spring交易处理。

First, Flyway has its own transaction managing system and does not use Spring transaction handling.

如果您的DAO扩展 JdbcDaoSupport ,您可以手动实例化您的DAO,然后在DAO中手动注入提供的 JdbcTemplate

If your DAOs extend JdbcDaoSupport, you could instantiate manually the your DAO and then manually inject the provided JdbcTemplate in the DAO:

public class MyJdbcMigration implements SpringJdbcMigration {
  public void migrate(JdbcTemplate jdbcTemplate) {
    MyJdbcDao dao = new MyJdbcDao();
    dao.setJdbcTemplate(jdbcTemplate);
    dao.updateDate();
  }
}

这篇关于用java飞行迁移的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-25 00:08