I am new to Spring boot, and I have a model like this:
package com.example.resource.type.req;
import java.util.Objects;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Embeddable;
import javax.validation.constraints.NotBlank;
import javax.persistence.Column;
import com.example.resource.annotation.EnumNamePattern;
@Embeddable
public class TodoItem {
public enum Status {
completed,
incomplete,
removed;
}
@NotBlank(message = "Name required")
public String name;
@NotBlank(message = "Description required")
public String description;
@Column(columnDefinition = "status")
@EnumNamePattern(regexp = "completed|incomplete|removed")
public Status status;
}
And I want to to run the following statement to create a enum type called status in the database:
CREATE TYPE status as ENUM ('completed', 'incomplete', 'removed');
Should I use Session.createNativeQuery() to run this, and where should I place? I am not sure as I only want this SQL to run once. Is there a better alternative?