Reputation: 34900
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?
Upvotes: 1
Views: 404
Reputation: 504
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");
}
Upvotes: 2