Liquibase插入日期数据报错:缺少java.util.Date(H2数据库)
I've run into similar compatibility issues between older Liquibase versions, Java 8, and H2 before. Here's how to resolve your error related to missing java.util.Date when inserting date values into the Aluno table:
Root Cause
Your Liquibase version (3.5.3) is quite outdated (released in 2017) and has known compatibility bugs with Java 8's date handling and newer H2 database versions. This leads to class loading issues when parsing date type fields during inserts.
Step-by-Step Fixes
1. Upgrade Liquibase to a Java 8-Compatible Version
Update your liquibase-core dependency to a stable, newer version that properly supports Java 8. Version 3.8.9 is a reliable choice here:
<dependency> <groupId>org.liquibase</groupId> <artifactId>liquibase-core</artifactId> <version>3.8.9</version> </dependency>
2. Pin H2 Database to a Compatible Version
Your H2 dependency doesn't specify a version, so Maven pulls the latest release by default. Newer H2 versions break compatibility with old Liquibase builds. Use a stable, compatible version like 1.4.199:
<dependency> <groupId>com.h2database</groupId> <artifactId>h2</artifactId> <version>1.4.199</version> </dependency>
3. Simplify Your Insert Script (Optional but Recommended)
You don't need to repeat the type attribute in your insert columns—Liquibase can infer the field type from your table schema. Removing these avoids potential type mismatches:
#popular Aluno - changeSet: id: 88801 author: Nicholas changes: - insert: columns: - column: name: AluId value: 1 - column: name: AluNome value: Mariana Celegati - column: name: AluEnd value: Rua Siqueira Bueno, 90 - column: name: AluCPF value: 44455522211 - column: name: AluBairro value: Mooca - column: name: AluCel value: 55552222 - column: name: AluTel value: 966662222 - column: name: AluDataEnt valueDate: 2017-02-15 - column: name: AluDataVenc valueDate: 2018-02-15 tableName: Aluno
Final Steps
After updating your dependencies and script, run mvn clean install to refresh your project's libraries, then re-execute your Liquibase migrations. This should resolve the java.util.Date missing error and successfully insert your date values into the H2 database.
内容的提问来源于stack exchange,提问作者Nicholas Maestrello Agiz

