LiquibaseException java.lang.ClassCastException: class java.time.LocalDateTime cannot be cast to class java.lang.String

Hello,

we are getting error with last version to mysql-connector-java (8.0.23) and liquibase(4.3.0), when we start the spring boot application. The error started when we updated mysql-connector-java (8.0.22) to mysql-connector-java (8.0.23). Looks like error with DATABASECHANGELOG table, DATEEXECUTED field.

nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘liquibase’ defined in class path resource [org/springframework/boot/autoconfigure/liquibase/LiquibaseAutoConfiguration$LiquibaseConfiguration.class]: Invocation of init method failed; nested exception is liquibase.exception.LiquibaseException: java.lang.ClassCastException: class java.time.LocalDateTime cannot be cast to class java.lang.String (java.time.LocalDateTime and java.lang.String are in module java.base of loader ‘bootstrap’)

We have the same problem. And it’s even more interesting because if you run your change log file first time everything is great. But after databasechangelog table created it stops working.
Have you find a solution?

Hello,

found solution switching to liquibase 4.3.1 version.

2 Likes

Thanks a lot. It’s worked out for me as well. I guess it was kind of a bug.

1 Like

I have exactly the same issue with liquibase-core v.3.10.3 and mysql-connector-java v.8.0.23.
Migrating to liquibase-core v.4.3.1 solved the problem.

For me working as well v.4.3.1. Thanks for the solution!

In case someone else runs into this issue, and if your project allows for the downgrade, you may try downgrading the jdbc driver used. I hit this error and reverted to use jdbc version 8.0.22 when I was using 8.0.25.

Thanks Diana, that worked for me too.

The exaception thrown to indicate that your code has attempted to cast an object to a subclass of which it is not an instance. This means that ClassCastException occurs when you try to cast an instance of an Object to a type that it is not. Type Casting 5 only works when the casted object follows an is a relationship to the type you are trying to cast to.

It is good practice to guard any explicit casts with an instanceof check first:

if (myApple instanceof Fruit) {
  Fruit myFruit = (Fruit)myApple;
}

When will be ClassCastException is thrown:

  • When you try to cast an object of Parent class to its Child class type, this exception will be thrown.

  • When you try to cast an object of one class into another class type that has not extended the other class or they don’t have any relationship between them