Liquibase 和 JPA 注释的实体
Liquibase and JPA annotated entities
我正在尝试将 Liquibase 与 JPA 注释一起使用,但我似乎没有用。
我的项目中有一个没有表的干净数据库和一个 JPA 实体。当我 运行 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>
当我 运行 生成更改日志任务时:
[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] ------------------------------------------------------------------------
Liquibase 正确地将目标数据库架构与您指定的变更日志进行比较....它是空的:-)
您需要做一些额外的工作。以下文章似乎很好地概述了使用 Hibernate 的 liquibase 的工作流程:
它看起来过于复杂,但 liquibase 正在做的是捕获对架构的所有更改。简而言之,您需要将您的数据库带到最新捕获的状态,生成增量,然后将此增量添加到您的源代码中。
希望对您有所帮助。
我正在尝试将 Liquibase 与 JPA 注释一起使用,但我似乎没有用。
我的项目中有一个没有表的干净数据库和一个 JPA 实体。当我 运行 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>
当我 运行 生成更改日志任务时:
[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] ------------------------------------------------------------------------
Liquibase 正确地将目标数据库架构与您指定的变更日志进行比较....它是空的:-)
您需要做一些额外的工作。以下文章似乎很好地概述了使用 Hibernate 的 liquibase 的工作流程:
它看起来过于复杂,但 liquibase 正在做的是捕获对架构的所有更改。简而言之,您需要将您的数据库带到最新捕获的状态,生成增量,然后将此增量添加到您的源代码中。
希望对您有所帮助。