我尝试将Liquibase与JPA注释一起使用,但好像没能成功。
我的项目中有一个干净的没有表格的数据库和一个JPA实体。当我运行liquibase diff时,它声称数据库已经是最新状态,但事实并非如此。
Liquibase插件的maven配置:
<plugins>
<plugin>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-maven-plugin</artifactId>
<version>3.3.1</version>
<configuration>
<changeLogFile>src/main/resources/liquibase/changelog.xml</changeLogFile>
<referenceUrl>hibernate:spring:com.mycompany.entity?dialect=org.hibernate.dialect.PostgreSQLDialect</referenceUrl>
<driver>org.postgresql.Driver</driver>
<url>jdbc:postgresql://localhost:5432/liqubase-test</url>
<username>postgres</username>
<password>postgres</password>
</configuration>
<executions>
<execution>
<phase>process-resources</phase>
<goals>
<goal>update</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.liquibase.ext</groupId>
<artifactId>liquibase-hibernate4</artifactId>
<version>3.4</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>4.1.4.RELEASE</version>
</dependency>
</dependencies>
</plugin>
</plugins>
changelog.xml文件:
<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.0.xsd">
</databaseChangeLog>
当我执行 generateChangeLog 任务时:
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building liqubase-sample 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- liquibase-maven-plugin:3.3.1:generateChangeLog (default-cli) @ liqubase-sample ---
[INFO] ------------------------------------------------------------------------
[INFO] Executing on Database: jdbc:postgresql://localhost:5432/liqubase-test
[INFO] Generating Change Log from database postgres @ jdbc:postgresql://localhost:5432/liqubase-test (Default Schema: public)
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog" xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.3.xsd http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd"/>
[INFO] Output written to Change Log file, null
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.213 s
[INFO] Finished at: 2015-01-10T14:47:24+01:00
[INFO] Final Memory: 9M/216M
[INFO] ------------------------------------------------------------------------