Hibernate : How to mapping a column with a enum type class ?

Look the example and see how mapping with hibernate annotation a enum type column.

Example :

/** User.java**/
@Entity
@Table(name = "usuario")
public class User {
@Enumerated(EnumType.STRING)
@Column(name = "perfil", length = 32)
@NotNull(message = "You need choose a perfil for this user")
private Perfil perfil;
}

/** Perfil Enum Class **/

public enum Perfil {
    ADMIN("Admin"),
    CLIENT("Client"),
    SALESMAN("Salesman");

    private final String label;

    private Perfil(String label) {
        this.label = label;
    }

    public String getLabel() {
        return label;
    }

}

			

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s