Currently i am using liquibase -> 4.3.2 and mysql -> 8.0.22 for my spring boot project. I am trying to create table through liquibase. It gets excuted first time . It creates 2 database by default . 1. databasechangelog and 2. databasechangeloglock . But when i try to run again then it gives me following error :
**Caused by: 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')**
Code for my db.changelog-1.0.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.8.xsd">
<changeSet id="1" author="auth1">
<sql>
CREATE TABLE user (
id BIGINT NOT NULL AUTO_INCREMENT,
fname VARCHAR(255) NOT NULL,
lname VARCHAR(255) NOT NULL,
email VARCHAR(255) NOT NULL,
number BIGINT NOT NULL,
password VARCHAR(255) NOT NULL,
role VARCHAR(255) NOT NULL,
CONSTRAINT PK_id PRIMARY KEY (id)
);
</sql>
<rollback>
DROP TABLE user;
</rollback>
</changeSet>
<changeSet id="2" author="auth1">
<sql>
CREATE TABLE plant (
plantname VARCHAR(50)
)
</sql>
<rollback>
DROP TABLE plant;
</rollback>
</changeSet>
</databaseChangeLog>
code for db.changelog-master.xml :
<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.8.xsd">
<include file="/db/changelog/db.changelog-1.0.xml"></include>
</databaseChangeLog>
application properties
spring.application.name = Cleandrop-Backend
spring.datasource.url = jdbc:mysql://localhost:3306/cleandrop?useUnicode=true&userLegacyDatetimeCode=false&serverTimezone=UTC&createDatabaseIfNotExist=true&allowPublicKeyRetrieval=true&useSSL=true
spring.datasource.username = root
spring.datasource.password = 1234
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.jpa.hibernate.ddl-auto=none
spring.liquibase.change-log=classpath:/db/changelog/db.changelog-master.xml
serverTimeZone=user-defined-time-zone
I also tried to change mysql version still same. How can i solve this?
LocalDateTime is an immutable date-time object that represents a date-time, often viewed as year-month-day-hour-minute-second. Other date and time fields, such as day-of-year, day-of-week and week-of-year, can also be accessed. Time is represented to nanosecond precision.
The easiest way to create an instance of the LocalDateTime class is by using the factory method of(), which accepts year, month, day, hour, minute, and second to create an instance of this class. A shortcut to create an instance of this class is by using atDate() and atTime() method of LocalDate and LocalTime class.
You can get the time from the LocaldateTime object using the toLocalTime() method. Therefore, another way to get the current time is to retrieve the current LocaldateTime object using the of() method of the same class. From this object get the time using the toLocalTime() method.
Other date fields, such as day-of-year, day-of-week and week-of-year, can also be accessed. For example, the value "2nd October 2007" can be stored in a LocalDate . This class does not store or represent a time or time-zone. Instead, it is a description of the date, as used for birthdays.
User mohiitg
commented that changing to liquibase version 4.3.1 resolved the issue.
As of 2021-05-03, version 4.3.5 was available. Updating to this version solved the error for me.
https://mvnrepository.com/artifact/org.liquibase/liquibase-core/4.3.5
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With