title: How can I convert a Hibernate String column to an Enum?
body: <p>I currently have a simple String field in a Hibernate persisted class:</p>
  
  <pre><code> private String font = "Times New Roman";
  </code></pre>
  
  <p>"Times New Roman" is the default value, so many stored objects have that data.  For several reasons, I would like to convert this to an Enum:</p>
  
  <pre><code> @Enumerated(EnumType.String)
   private FontEnum font = FontEnum.TIMES;
  </code></pre>
  
  <p>Hibernate uses Enum.valueOf(clazz, string) to convert the column data, which would fail on "Times New Roman" due to the spaces.</p>
  
  <p>Googling suggests overriding Enum.valueOf() is impossible; do others know differently?  Can I fool Enum.valueOf() to convert "Times New Roman" to FontEnum.TIMES?</p>
  
  <p>Or, can I create a custom Hibernate converter like:</p>
  
  <pre><code> public FontEnum legacyConverter(String old);
  </code></pre>
  
  <p>and add</p>
  
  <pre><code> @Enumerated(EnumType.String)
   @Converter(Converters.legacyConverter()) // Does this exist?
   private FontEnum font = FontEnum.TIMES;
  </code></pre>
  
  <p>to my fields?  I haven't seen anything like that.</p>
  
  <p>I know a fallback method would be to add some pre-persist logic that slowly migrates the data to another column, but I'd like to avoid that.</p>
  
  <p>Thank you - it's my first question on StackOverflow!</p>