【问题标题】:Liquibase cannot find my entity classes to generate diff in spring projectLiquibase 在 spring 项目中找不到我的实体类来生成差异
【发布时间】:2018-06-11 13:24:12
【问题描述】:

Liquibase 在给定的包中找不到我的实体类(JPA 注释)来生成差异。

当我使用mvn liquibase:diff 命令时,它说没有发现更改,无事可做,但我的实体有新字段

我使用 spring framweork、JPA(hibernate)、Liquibase、liquibase-hibernate

这是我的代码:

liquibase.properties

referenceUrl=hibernate:spring:model.entity.persistent?dialect=org.hibernate.dialect.OracleDialect
changeLogFile=src/main/resources/liquibase-changeLog.xml
url=jdbc:oracle:thin:@localhost:1521:xe
username=username
password=password
driver=oracle.jdbc.OracleDriver
diffChangeLogFile=src/main/resources/liquibase-diff-changeLog-8.xml

pom.xml liquibase-hibernate 配置

<plugin>
            <groupId>org.liquibase</groupId>
            <artifactId>liquibase-maven-plugin</artifactId>
            <version>3.5.3</version>
            <configuration>
                <propertyFile>src/main/resources/liquibase.properties</propertyFile>
            </configuration>
            <executions>
                <execution>
                    <goals>
                        <goal>update</goal>
                    </goals>
                </execution>
            </executions>
            <dependencies>
                <dependency>
                    <groupId>org.liquibase.ext</groupId>
                    <artifactId>liquibase-hibernate4</artifactId>
                    <version>3.5</version>
                </dependency>
                <dependency>
                    <groupId>org.springframework</groupId>
                    <artifactId>spring-beans</artifactId>
                    <version>4.1.7.RELEASE</version>
                </dependency>
                <dependency>
                    <groupId>org.springframework.data</groupId>
                    <artifactId>spring-data-jpa</artifactId>
                    <version>1.7.3.RELEASE</version>
                </dependency>


                <dependency>
                    <groupId>org.springframework</groupId>
                    <artifactId>spring-jdbc</artifactId>
                    <version>2.0.6</version>
                </dependency>

                <dependency>
                    <groupId>org.yaml</groupId>
                    <artifactId>snakeyaml</artifactId>
                    <version>1.19</version>
                </dependency>

            </dependencies>
        </plugin>

【问题讨论】:

    标签: spring hibernate database-migration liquibase liquibase-hibernate


    【解决方案1】:

    我尝试了以下..

    pom.xml

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.liquibase</groupId>
                <artifactId>liquibase-maven-plugin</artifactId>
                <version>3.5.3</version>
                <configuration>
                    <propertyFile>liquibase.properties</propertyFile>
                    <changeLogFile>changelogs/db.changelog-master.xml</changeLogFile>
                </configuration>
                <executions>
                    <execution>
                        <phase>process-resources</phase>
                    </execution>
                </executions>
                <dependencies>
                    <dependency>
                        <groupId>org.liquibase.ext</groupId>
                        <artifactId>liquibase-hibernate5</artifactId>
                        <version>3.6</version>
                    </dependency>
                    <dependency>
                        <groupId>org.springframework</groupId>
                        <artifactId>spring-beans</artifactId>
                        <version>4.1.7.RELEASE</version>
                    </dependency>
                    <dependency>
                        <groupId>org.springframework.data</groupId>
                        <artifactId>spring-data-jpa</artifactId>
                        <version>1.7.3.RELEASE</version>
                    </dependency>
                    <dependency>
                        <groupId>org.springframework</groupId>
                        <artifactId>spring-jdbc</artifactId>
                        <version>2.0.6</version>
                    </dependency>
                    <dependency>
                        <groupId>javax.xml.bind</groupId>
                        <artifactId>jaxb-api</artifactId>
                        <version>2.2.11</version>
                    </dependency>
                    <dependency>
                        <groupId>org.yaml</groupId>
                        <artifactId>snakeyaml</artifactId>
                        <version>1.19</version>
                    </dependency>
                </dependencies>
            </plugin>
    
        </plugins>
    </build>
    

    liquibase.properties

    referenceUrl=hibernate:spring:ch.karthi.liquibase.jpa.update.entities?dialect=org.hibernate.dialect.MySQL5Dialect
        referenceDriver=liquibase.ext.hibernate.database.connection.HibernateDriver
        referenceDefaultSchemaName=liquibasetest
        driver=com.mysql.jdbc.Driver
        url=jdbc:mysql://127.0.0.1:3306/liquibasetest
        username=USERNAME
        password=PASSWORD
        defaultSchemaName=liquibasetest
        changeLogFile=src/main/resources/liquibase-changeLog.xml
        diffChangeLogFile=src/main/resources/liquibase-diff-changeLog-8.xml
        outputChangeLogFile=src/main/resources/liquibase-changeLog.xml
    

    它没有任何问题。

     [INFO] Scanning for projects...
        [INFO]                                                                         
        [INFO] ------------------------------------------------------------------------
        [INFO] Building liquibase-jpa-update 0.0.1-SNAPSHOT
        [INFO] ------------------------------------------------------------------------
        [INFO] 
        [INFO] --- liquibase-maven-plugin:3.5.3:diff (default-cli) @ liquibase-jpa-update ---
        [INFO] ------------------------------------------------------------------------
        [INFO] Parsing Liquibase Properties File
        [INFO]   File: liquibase.properties
        [INFO]   'outputChangeLogFile' in properties file is not being used by this task.
        [INFO] ------------------------------------------------------------------------
        [INFO] Executing on Database: jdbc:mysql://127.0.0.1:3306/liquibasetest
    
    INFO 05.01.18, 12:58: liquibase-hibernate: Reading hibernate configuration hibernate:spring:ch.karthi.liquibase.jpa.update.entities?dialect=org.hibernate.dialect.MySQL5Dialect
    INFO 05.01.18, 12:58: liquibase-hibernate: Found package ch.karthi.liquibase.jpa.update.entities
    log4j:WARN No appenders could be found for logger (org.jboss.logging).
    log4j:WARN Please initialize the log4j system properly.
    WARNING: An illegal reflective access operation has occurred
    WARNING: Please consider reporting this to the maintainers of javassist.util.proxy.SecurityActions
    WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
    WARNING: All illegal access operations will be denied in a future release
    INFO 05.01.18, 12:58: liquibase-hibernate: Using dialect org.hibernate.dialect.MySQL5Dialect
    [INFO] Performing Diff on database root@localhost @ jdbc:mysql://127.0.0.1:3306/liquibasetest (Default Schema: liquibasetest)
    INFO 05.01.18, 12:58: liquibase-hibernate: Found table Customer
    INFO 05.01.18, 12:58: liquibase-hibernate: Found table Customer
    INFO 05.01.18, 12:58: liquibase-hibernate: Found table Customer
    INFO 05.01.18, 12:58: liquibase-hibernate: Found primary key CustomerPK
    INFO 05.01.18, 12:58: liquibase-hibernate: Found column id integer
    INFO 05.01.18, 12:58: liquibase-hibernate: Found column age integer
    INFO 05.01.18, 12:58: liquibase-hibernate: Found column name varchar(255)
    INFO 05.01.18, 12:58: liquibase-hibernate: Found column sexString varchar(255)
    INFO 05.01.18, 12:58: liquibase: src/main/resources/liquibase-diff-changeLog-8.xml exists, appending
    [INFO] Differences written to Change Log File, src/main/resources/liquibase-diff-changeLog-8.xml
    [INFO] ------------------------------------------------------------------------
    [INFO] 
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD SUCCESS
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time: 4.328 s
    [INFO] Finished at: 2018-01-05T12:58:37+01:00
    [INFO] Final Memory: 25M/85M
    [INFO] ------------------------------------------------------------------------
    

    【讨论】:

    • 新 jpa 实体有什么不同吗?我的意思是它是在为创建表创建变更集吗?
    猜你喜欢
    • 2019-07-13
    • 2023-01-13
    • 1970-01-01
    • 2016-06-13
    • 1970-01-01
    • 2017-12-05
    • 1970-01-01
    • 1970-01-01
    • 2014-05-10
    相关资源
    最近更新 更多