我的项目基于Tapestry
框架。它使用Hibernate
作为ORM库。
我的类使用annotations
映射到数据库。
我想将Liquibase
集成到我的项目中,以便能够维护数据库状态,进行版本更新。
到目前为止,我所做的是以下步骤:
1)我创建了服务对:LiquibaseService
- > LiquibaseServiceImpl
。
LiquibaseSerivce
有方法public void update()
,可以从DataSource
配置创建独立hibernate.cfg.xml
,最后liquibase.update("production");
2)我在AppModule
中添加了对此服务的绑定:
binder.bind(LiquibaseService.class, LiquibaseServiceImpl.class).eagerLoad();
3)我已将initMyApplication
方法添加到AppModule
开始Liquibase
更新:
@Startup
public static void initMyApplication(Logger logger, LiquibaseService liquibaseService) {
logger.info("Updating database by liquibase service...");
liquibaseService.update();
logger.info("update-db done.");
}
所有这些都适用于生产,其中已经创建了初始方案:我可以放心地删除表格,列等等。
但问题是,在将应用程序部署到新服务器时,我无法从零(使用Liquibase
)创建新方案:Hibernate
独立启动并抱怨,没有映射任何表我的班级在计划中。
在Hibernate
完成工作的那一刻,我怎样才能放慢Liquibase
的速度?
答案 0 :(得分:2)
您可以执行类似此操作的
,而不是使用@Startup public static void contributeRegistryStartup(
final Logger logger, final LiquibaseService liquibaseService,
OrderedConfiguration<Runnable> configuration)
{
configuration.add("Liquibase", new Runnable()
{
public void run()
{
logger.info("Updating database by liquibase service...");
liquibaseService.update();
logger.info("update-db done.");
}
}, "after:HibernateStartup");
}