我尝试在 Hibernate 实体和 mysql 数据库上使用 mvn liquibase:diff 。构建因奇怪的异常而失败:无法调用“java.sql.ResultSet.next()”,因为“schemas”为空。我的 liquibase.properties:
driver:com.mysql.cj.jdbc.Driver
changeLogFile:src/main/resources/db/changelog/dbchangelog.xml
url:jdbc:mysql://localhost:3306/liquibase
defaultSchemaName:liquibase
username:liquibase
password:liquibase
hibernate.dialect:org.hibernate.dialect.MySQL8Dialect
referenceUrl:hibernate:org.heller.liqibase.entity?dialect=org.hibernate.dialect.MySQL8Dialect
referenceDefaultSchema:hibernate
pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.2.5</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<groupId>org.heller.liquibase</groupId>
<artifactId>liquibase</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>liquibase</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>17</java.version>
<liquibase.version>4.27.0</liquibase.version>
<liquibase-hibernate6.version>4.27.0</liquibase-hibernate6.version>
<hibernate6.version>6.1.5.Final</hibernate6.version>
<javassist.version>3.24.0-GA</javassist.version>
<validation-api.version>3.0.2</validation-api.version>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<maven.build.timestamp.format>yyyyMMddHHmmss</maven.build.timestamp.format>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>6.3.1.Final</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<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>4.27.0</version>
<configuration>
<propertyFile>liquibase.properties</propertyFile>
</configuration>
<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.33</version>
</dependency>
<dependency>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-core</artifactId>
<version>${liquibase.version}</version>
</dependency>
<dependency>
<groupId>org.liquibase.ext</groupId>
<artifactId>liquibase-hibernate6</artifactId>
<version>${liquibase-hibernate6.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
<version>3.2.5</version>
</dependency>
<dependency>
<groupId>jakarta.validation</groupId>
<artifactId>jakarta.validation-api</artifactId>
<version>${validation-api.version}</version>
</dependency>
<dependency>
<groupId>org.javassist</groupId>
<artifactId>javassist</artifactId>
<version>${javassist.version}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</project>
命令行错误:
有人可以告诉我如何解决这个问题吗?
问题出在 liquibase.properties 中。这个例子可能有效:
driver:com.mysql.cj.jdbc.Driver
#changeLogFile:src/main/resources/db/changelog/dbchangelog.xml
url:jdbc:mysql://localhost:3306/liquibase
liquibaseSchemaName:liquibase
username:liquibase
password:liquibase
hibernate.dialect:org.hibernate.dialect.MySQL8Dialect
referenceUrl:hibernate:spring:org.heller.liqibase.entity?dialect=org.hibernate.dialect.MySQL8Dialect
referenceDefaultSchema:hibernate
这是我的 pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.2.5</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<groupId>org.heller.liquibase</groupId>
<artifactId>liquibase</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>liquibase</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>17</java.version>
<liquibase.version>4.27.0</liquibase.version>
<liquibase-hibernate6.version>4.27.0</liquibase-hibernate6.version>
<hibernate6.version>6.1.5.Final</hibernate6.version>
<javassist.version>3.24.0-GA</javassist.version>
<validation-api.version>3.0.2</validation-api.version>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<maven.build.timestamp.format>yyyyMMddHHmmss</maven.build.timestamp.format>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>6.3.1.Final</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<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>4.27.0</version>
<configuration>
<changeLogFile>src/main/resources/dbchangelog.xml</changeLogFile>
<propertyFile>liquibase.properties</propertyFile>
<diffChangeLogFile>
src/main/resources/updates/${maven.build.timestamp}-changeLog.xml
</diffChangeLogFile>
<logging>debug</logging>
</configuration>
<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.33</version>
</dependency>
<dependency>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-core</artifactId>
<version>${liquibase.version}</version>
</dependency>
<dependency>
<groupId>org.liquibase.ext</groupId>
<artifactId>liquibase-hibernate6</artifactId>
<version>${liquibase-hibernate6.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
<version>3.2.5</version>
</dependency>
<dependency>
<groupId>jakarta.validation</groupId>
<artifactId>jakarta.validation-api</artifactId>
<version>${validation-api.version}</version>
</dependency>
<dependency>
<groupId>org.javassist</groupId>
<artifactId>javassist</artifactId>
<version>${javassist.version}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</project>