Spring Boot Kotlin + Hibernate продолжает выдавать исключение SQLSyntaxErrorException - PullRequest
0 голосов
/ 24 июня 2019

Весенний ботинок Hibernate продолжаю бросать SQLSyntaxErrorException.Я проверил мои переменные / имя столбца для любого зарезервированного слова MYSQL.Также я проверил, что таблицы были созданы в базе данных, таким образом, ошибка table not found не имеет смысла.

Источник данных Spring DDL-AUTO установлен на create-drop

Ниже приведено исключение

2019-06-25 02:21:29.985  WARN 2476 --- [  restartedMain] o.h.t.s.i.ExceptionHandlerLoggedImpl     : GenerationTarget encountered exception accepting command : Error executing DDL "alter table file_object drop foreign key FKak0hsl4myvh4c4tybk8lnqifa" via JDBC Statement

org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL "alter table file_object drop foreign key FKak0hsl4myvh4c4tybk8lnqifa" via JDBC Statement
...
Caused by: java.sql.SQLSyntaxErrorException: Table 'assignment_controller.file_object' doesn't exist
2019-06-25 02:21:29.989  WARN 2476 --- [  restartedMain] o.h.t.s.i.ExceptionHandlerLoggedImpl     : GenerationTarget encountered exception accepting command : Error executing DDL "alter table file_object drop foreign key FKlw0yhw41h74vrc7b12rkhwh2o" via JDBC Statement

org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL "alter table file_object drop foreign key FKlw0yhw41h74vrc7b12rkhwh2o" via JDBC Statement
...
Caused by: java.sql.SQLSyntaxErrorException: Table 'assignment_controller.file_object' doesn't exist
2019-06-25 02:21:29.993  WARN 2476 --- [  restartedMain] o.h.t.s.i.ExceptionHandlerLoggedImpl     : GenerationTarget encountered exception accepting command : Error executing DDL "alter table submission drop foreign key FKd14f6dkvk641qmivfhi4s31xd" via JDBC Statement

org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL "alter table submission drop foreign key FKd14f6dkvk641qmivfhi4s31xd" via JDBC Statement
...
Caused by: java.sql.SQLSyntaxErrorException: Table 'assignment_controller.submission' doesn't exist

Это мой дизайн сущности

@Entity
class Task(
        ...
        @OneToMany(cascade = [CascadeType.ALL], orphanRemoval = true, mappedBy = "task")
        var testcases: MutableList<TestCase> = mutableListOf(),

        @OneToMany(cascade = [CascadeType.ALL], orphanRemoval = true, mappedBy = "task")
        var submission: MutableList<Submission> = mutableListOf(),

        @Version
        @ColumnDefault("0")
        var version: Int = 0
) : AbstractAuditorEntity()

@Entity
class TestCase(
        ...
        @Column(nullable = false)
        @Enumerated(EnumType.STRING)
        var testCaseType: TestCaseType = TestCaseType.PRIVATE,

        @OneToMany(mappedBy = "testcase")
        var testfile: MutableList<FileObject> = mutableListOf(),

        @ManyToOne(fetch = FetchType.LAZY)
        @JoinColumn(name = "fk_task")
        var task: Task? = null

) : AbstractAuditorEntity()

@Entity
class FileObject(
        ...
        @ManyToOne(fetch = FetchType.LAZY)
        @JoinColumn(name = "fk_testcase")
        var testcase: TestCase? = null,

        @ManyToOne(fetch = FetchType.LAZY)
        @JoinColumn(name = "fk_submission")
        var submission: Submission? = null

) : AbstractAuditorEntity()

@Entity
class Submission(
        ...
        @OneToMany(mappedBy = "submission")
        var files: MutableList<FileObject> = mutableListOf(),

        @ManyToOne(fetch = FetchType.LAZY)
        @JoinColumn(name = "fk_task")
        var task: Task? = null

): AbstractAuditorEntity()

ОБНОВЛЕНИЕ 1: если я установлю DDL-AUTO в update вместо create-dropисключение не выдается.

ОБНОВЛЕНИЕ 2 : Это операторы создания таблицы. ОНИ АВТОМАТИЗИРОВАНЫ HIBERNATE Полное исключение см .: https://pastebin.com/byD0Vh5W

create table submission
(
    id          bigint auto_increment
        primary key,
    created     datetime         not null,
    deleted     bit default b'0' not null,
    hidden      bit default b'0' not null,
    locked      bit default b'0' not null,
    modified    datetime         not null,
    created_by  varchar(255)     not null,
    modified_by varchar(255)     not null,
    lang        varchar(255)     null,
    fk_task     bigint           null,
    constraint FKd14f6dkvk641qmivfhi4s31xd
        foreign key (fk_task) references task (id)
);

create table file_object
(
    id            bigint auto_increment
        primary key,
    created       datetime            not null,
    deleted       bit    default b'0' not null,
    hidden        bit    default b'0' not null,
    locked        bit    default b'0' not null,
    modified      datetime            not null,
    created_by    varchar(255)        not null,
    modified_by   varchar(255)        not null,
    bucket        varchar(255)        not null,
    content_type  varchar(255)        not null,
    object_key    varchar(255)        not null,
    original_name varchar(255)        not null,
    size          bigint default 0    not null,
    fk_submission bigint              null,
    fk_testcase   bigint              null,
    constraint FKak0hsl4myvh4c4tybk8lnqifa
        foreign key (fk_submission) references submission (id),
    constraint FKlw0yhw41h74vrc7b12rkhwh2o
        foreign key (fk_testcase) references test_case (id)
);

create table task
(
    id          bigint auto_increment
        primary key,
    created     datetime         not null,
    deleted     bit default b'0' not null,
    hidden      bit default b'0' not null,
    locked      bit default b'0' not null,
    modified    datetime         not null,
    created_by  varchar(255)     not null,
    modified_by varchar(255)     not null,
    task_name   varchar(255)     not null,
    task_type   varchar(255)     not null,
    uuid        varchar(255)     not null,
    version     int default 0    not null
);

create table test_case
(
    id             bigint auto_increment
        primary key,
    created        datetime         not null,
    deleted        bit default b'0' not null,
    hidden         bit default b'0' not null,
    locked         bit default b'0' not null,
    modified       datetime         not null,
    created_by     varchar(255)     not null,
    modified_by    varchar(255)     not null,
    score          int              not null,
    test_case_name varchar(255)     not null,
    test_case_type varchar(255)     not null,
    fk_task        bigint           null,
    constraint FKeqki4pkxcpw55ksc7m2g531m8
        foreign key (fk_task) references task (id)
);

ОБНОВЛЕНИЕ 3 : Это мое приложение .yml

spring:
  datasource:
    url: jdbc:mysql://${DATABASE_HOSTNAME:localhost}:${DATABASE_PORT:3306}/${DATABASE_NAME:assignment_controller}?createDatabaseIfNotExist=true&characterEncoding=UTF-8&allowPublicKeyRetrieval=true&useSSL=false&${DATABASE_ARGS:}
    username: ${DATABASE_USERNAME:root}
    password: ${DATABASE_PASSWORD:123456}
    driver-class-name: com.mysql.cj.jdbc.Driver

  jpa:
    open-in-view: true
    hibernate:
      ddl-auto: ${DDL_MODE:update}

    properties:
      hibernate:
        dialect: org.hibernate.dialect.MySQL5InnoDBDialect
        connection:
          characterEncoding: utf-8
          CharSet: utf-8
          useUnicode: true
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...