我试图将Liquibase和JPA注释一起使用,但我似乎没有用。
我的项目中没有表和一个JPA实体的干净DB。当我运行liquibase diff时,它声称DB是最新的 - 但它根本不是真的。
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] ------------------------------------------------------------------------
答案 0 :(得分:4)
Liquibase正确地将目标数据库架构与您指定的更改日志进行比较....这是空的: - )
你需要做一些额外的工作。以下文章似乎在概述liquibase与Hibernate的工作流程方面做得很好:
它似乎过于复杂,但liquibase正在做的是捕获对架构的所有更改。简而言之,您需要将DB带到最新捕获状态,生成增量,然后将此增量添加到源代码中。
我希望这会有所帮助。