How to set an entity with enum column with default property value in SpringBoot

Issue

I am using Springboot 2.7.2with Hibernate and Mysql 8. Is there a way to make an Entity class so as to execute a create table Query like this.

CREATE TABLE `settings` (
    `SettingsId` enum('1') NOT NULL,
    ................,
    ................,
     PRIMARY KEY (`SettingsId`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1

Solution

I have got the answer from here and made the Entity Class like this

@Entity
public class Settings {
    public enum SettingsId {
    }

    @Id
    @Enumerated(EnumType.STRING)
    @Column(columnDefinition = "ENUM('1')")
    private SettingsId settingsId;

    ........;
    ........;
}

Answered By – Renoj Joseph

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published