skip to Main Content

I am using Springboot JPAs to generate a MySql8 table. It works fine unless I try to use the columndefinition in the Column annotation.

 @Column(columnDefinition = "boolean default false")
    private Boolean example;

I tried replacing boolean with TINYINT but MySql8 should support boolean as far as I am aware.

I get an error during the table generation:

Caused by: java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘boolean default false at line 5

To me it looks like the generated SQL Syntax has additional quotation marks but I am unsure how to fix the issue.

 create table `exampleTable` (
       `id` bigint not null auto_increment,
        `example` `boolean default false`,
        primary key (`id`)
    )

EDIT:
I found my Issue in this question:
Spring JPA globally_quoted_identifiers incorrectly quoting column type TEXT

2

Answers


  1. if you want to set the default value of the example to be false then you can write it like this and remove columnDefintion from there

    private Boolean example=false;

    Login or Signup to reply.
  2. Disable quotes by adding spring.jpa.properties.hibernate.globally_quoted_identifiers=false to application.properties file

    But after disabling, you will not be able to use column and table names that match mysql keywords (eg desc). Workaround by adding an underscore:

    @Column(name = "desc_")
    String desc;
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search