dedjer / lab-springboot-enum

Using enum properties in your POJOs and saving to an H2 database

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

lab-springboot-enum

Created this project to see what value gets stored in the database when a property is set to an enum type.

Enum.class

public class Enum {
    public enum Status{
        ENROLLED,
        WITHDRAW,
        SUSPENDED,
        GRADUATED,
        TRANSFERRED
    }
}

Student.class

@Entity
public class Student {

    @Id
    @GeneratedValue
    private Long Id;
    private String name;
    private String passportNumber;

    @Enumerated(EnumType.STRING)
    private Enum.Status status;
 }   

By default the "status" field will be create as an int in the database.

The @Enumerated annotation tells Jpa to create the field as a character field.

Spring Boot

Project generated at http://start.spring.io using Spring Initialzr

Maven Dependencies

Project was created with the following maven dependencies:

  • JPA
  • REST
  • Hal
  • HATEOS
  • H2

About

Using enum properties in your POJOs and saving to an H2 database


Languages

Language:Java 100.0%