我有一个使用JPA进行持久化的Java项目。 现在我想将LiquiBase集成到我的项目中,但我不知道如何更改JPA/Liquibase的执行顺序。Liquibase + JPA:运行订单
为清楚: 到现在为止我的persistence.xml看起来是这样的:
<property name="javax.persistence.jdbc.driver" value="org.h2.Driver"/>
<property name="javax.persistence.jdbc.url" value=.../>
<property name="javax.persistence.jdbc.user" value=.../>
<property name="eclipselink.ddl-generation" value="create-or-extend-tables"/>
我现在试图设置:
<property name="eclipselink.ddl-generation" value="none"/>
使liquibase处理所有数据库的东西。
但现在当我运行我的代码时,JPA会抛出一个错误,因为有些表缺失,尽管这些表应该由liquibase创建,这使我相信JPA在liquibase之前运行。
如何更改该订单? 直到现在,Liquibase在代码通过此行执行:
java.sql.Connection connection = openConnection(); //your openConnection logic here
Database database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(new JdbcConnection(connection));
Liquibase liquibase = new liquibase.Liquibase("path/to/changelog.xml", new ClassLoaderResourceAccessor(), database);
liquibase.update(new Contexts(), new LabelExpression());
我读的地方,这可以通过Liquibase Servlet的监听器来实现,但这需要数据库的数据源,并且我不知道怎么去说。
Liquibase本身工作正常。
这是一个Java EE还是Spring应用程序? – Puce
它的Java EE项目:) – Crucios