与Tapestry和Hibernate集成的Liquibase:初始模式创建步骤 [英] Liquibase integrated with a Tapestry and Hibernate: initial schema creation step
问题描述
我有基于 Tapestry
框架的项目。它使用 Hibernate
作为ORM库。
我的类使用注释映射到数据库
。
我想将 Liquibase
集成到我的项目中,以便维护数据库状态,做版本更新。
直到现在我做了以下步骤:
1)我创建了服务对: LiquibaseService
- > LiquibaseServiceImpl
。
LiquibaseSerivce
有方法 public void update()
,它创建独立的 DataSource 从 hibernate.cfg.xml
配置并最终执行 liquibase.update(production);
$ b 2)我在 AppModule
中添加了对此服务的绑定:
binder.bind(LiquibaseService.class,LiquibaseServiceImpl.class).eagerLoad();
3)我已经将 initMyApplication
方法添加到 AppModule
开始 Liquibase
更新:
@Startup
public static void initMyApplication(Logger logger,LiquibaseService liquibaseService){
logger.info(通过liquibase服务更新数据库...);
liquibaseService.update();
logger.info(update-db done。);
所有这些工作正常生产,其中最初的方案已经创建:我可以舒适的放置表格,列等等。
但问题是我无法从零创建新方案(使用 Liquibase
)将应用程序部署到新服务器时: Hibernate
独立启动,抱怨,没有任何表映射我的课程。
如何减慢 Hibernate
直到 Liquibase
会完成它的工作吗? @Startup你可以做这样的事情:
pre $ public static void contributeRegistryStartup(
final Logger logger,final LiquibaseService liquibaseService,
OrderedConfiguration< Runnable>配置)
{
configuration.add(Liquibase,new Runna ble()
{
public void run()
{
logger.info(通过liquibase服务更新数据库...);
liquibaseService.update();
logger.info(update-db done。);
}
},after:HibernateStartup);
}
I have the project based on Tapestry
framework. It uses Hibernate
as ORM library.
My classes are mapped to database using annotations
.
I would like to integrate Liquibase
into my project to be able to maintance database state, doing version updates.
What I have done till this moment is the following steps:
1) I've created service pair: LiquibaseService
-> LiquibaseServiceImpl
.
LiquibaseSerivce
has method public void update()
, which creates independent DataSource
from hibernate.cfg.xml
configuration and finally does liquibase.update("production");
2) I've added binding to this service in AppModule
:
binder.bind(LiquibaseService.class, LiquibaseServiceImpl.class).eagerLoad();
3) I've added initMyApplication
method to AppModule
which starts Liquibase
update:
@Startup
public static void initMyApplication(Logger logger, LiquibaseService liquibaseService) {
logger.info("Updating database by liquibase service...");
liquibaseService.update();
logger.info("update-db done.");
}
All this works fine on production, where initial scheme was already created: I can comfortable drop tables, columns and so on.
But the issue is that I can not create new scheme from zero (using Liquibase
) when deploying application to a new server: Hibernate
starts independently ans complains, that there aren't any tables mapped to my class in the scheme.
How can I slow down Hibernate
starting until that moment when Liquibase
will finish its job?
解决方案 Instead of using @Startup you can do something like this
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");
}
这篇关于与Tapestry和Hibernate集成的Liquibase:初始模式创建步骤的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!