gpt4 book ai didi

jpa - Liquibase 和 JPA 注释实体

转载 作者:行者123 更新时间:2023-12-04 15:48:50 27 4
gpt4 key购买 nike

我正在尝试将 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>

当我运行 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] ------------------------------------------------------------------------

最佳答案

Liquibase 正确地将目标数据库架构与您指定的更改日志进行比较......这是空的:-)

你需要做一些额外的工作。以下文章似乎很好地概述了 liquibase 与 Hibernate 的工作流程:

  • http://www.operatornew.com/2012/11/automatic-db-migration-for-java-web.html

  • 它看起来过于复杂,但 liquibase 正在做的是捕获对架构的所有更改。简而言之,您需要将数据库带到最新捕获的状态,生成增量,然后将此增量添加到您的源代码中。

    我希望这有帮助。

    关于jpa - Liquibase 和 JPA 注释实体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27877154/

    27 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com