0

H2環境では型変換ができていたのですが、My SQLに切り替えた段階でエラーとなってしまいます。
どこをどうやって修正すればいいか、調べてもよくわかりませんでした。
ご助力いただけると助かります。

・以下環境

plugins {
    id 'java'
    id 'org.springframework.boot' version '2.7.8-SNAPSHOT'
    id 'io.spring.dependency-management' version '1.0.15.RELEASE'
}

group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'

repositories {
    mavenCentral()
    maven { url 'https://repo.spring.io/milestone' }
    maven { url 'https://repo.spring.io/snapshot' }
}

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-jdbc'
    implementation 'org.springframework.boot:spring-boot-starter-security'
    implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
    implementation 'org.springframework.boot:spring-boot-starter-validation'
    implementation 'org.springframework.boot:spring-boot-starter-web'
    implementation 'org.thymeleaf.extras:thymeleaf-extras-springsecurity5'
    developmentOnly 'org.springframework.boot:spring-boot-devtools'
    runtimeOnly 'com.h2database:h2'
    runtimeOnly 'com.mysql:mysql-connector-j'
        testImplementation('org.springframework.boot:spring-boot-starter-test') {
        exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
    }
    testImplementation 'org.springframework.security:spring-security-test'
    testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
    testImplementation('org.mockito:mockito-core:3.6.0')
    testImplementation('org.mockito:mockito-junit-jupiter:3.6.0')
}

tasks.named('test') {
    useJUnitPlatform()
}

・以下エラーとなるDaoImplファイルの記述箇所

task.setDeadline(((Timestamp) result.get("deadline")).toLocalDateTime());

・以下エラー内容

java.lang.ClassCastException: class java.time.LocalDateTime cannot be
cast to class java.sql.Timestamp (java.time.LocalDateTime is in module
java.base of loader 'bootstrap'; java.sql.Timestamp is in module
java.sql of loader 'platform')

・実行したSQL

CREATE TABLE task
(
    id INT NOT NULL AUTO_INCREMENT,
    user_id INT NOT NULL,
    type_id INT NOT NULL,
    title VARCHAR(50) NOT NULL,
    detail TEXT,
    deadline DATETIME NOT NULL,
    PRIMARY KEY(id)
);

1 件の回答 1

1

以下修正で対応ができました。

task.setDeadline((LocalDateTime)result.get("deadline"));

この質問に回答するには、ログインする必要があります。

求めていた回答ではありませんか? のタグが付いた他の質問を参照する。