title: hibernate - automatic conversion of column value (string to enum)
body: <p>Is there any way to do something like this. I have an entity called person.</p>
  
  <pre><code>@Entity
  @Table(name = "PERSON")
  public class Person {
     @Column(name = "NAME", length = 128, columnDefinition = "VARCHAR2(128)")
     String name;
     @Column(name = "NATIONALITY", length = 128, columnDefinition = "VARCHAR2(128)")
     String nationality;
  }
  </code></pre>
  
  <p>The 'NATIONALITY' column has numeric values - every number is a code of a country. I would like to map the 'nationality' field to my custom enum and create some method transforming code&lt;->country.</p>
  
  <pre><code>@Entity
  @Table(name = "PERSON")
  public class Person {
     @Column(name = "NAME", length = 128, columnDefinition = "VARCHAR2(128)")
     String name;
     @Column(name = "NATIONALITY", length = 128, columnDefinition = "VARCHAR2(128)")
     Nationality nationality;
  }
  
  enum Nationality {
     USA, Brazil, Germany; // etc.
  }
  
  public static Nationality codeToNationality(String code);
  </code></pre>
  
  <p>Is there any hibernate methods for something like this? I can't modify columns definitions - the database is read only.</p>
  
  <p>The second thing I'd like to achieve is to exclude any entities of unresolved nationality codes. The entities of codeToNationality(...) == null would be invisible to hibernate.</p>
  
  <p>My model (persons, nationalities) is only an example.</p>
  
  <p>Thanks for any help!</p>