Skip to content

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

Notifications You must be signed in to change notification settings

dedjer/lab-springboot-enum

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages