title: Mapping Table Rows to Enum Values in Hibernate 4
body: <p>I have a table <code>roles</code> which has values such as <code>admin</code>, <code>user</code>, and others. I do not want to make it an <code>ENUM</code> type because I think the list might grow, shrink or change in the near future. I can't figure out a way to get Hibernate to Map directly to their respective enum types in my code automatically when I get the queried object.</p>
  
  <p>Is there a standard approach to this?</p>
  
  <p>EDIT: So basically, instead of storing the string in the row (which is what is on the DB), I want it to store the Enum when I query the DB.</p>
  
  <pre><code>public class enum UserType {
  Admin("Admin"),
  User("User");
  
  private final String userType;
  
  UserType(String userType) {
      this.userType = userType;
  }
  
  @Override
  public String toString() {
      return userType;
  }
  }
  @Entity
  @Table(name = "user")
  public class User {
      private Int id;
      private UserType userType;
  
  public Int getId() {
      return id;
  }
  public void setId(Int id) {
      this.id = id;
  }
  public UserType getUserType() {
      return userType;
  }
  public void setUserType(UserType userType) {
      this.userType = userType;
  }
  </code></pre>
  
  <p>}</p>