title: Make hibernate call a different method than valueof() when persisting enums
body: <p>I'm trying to retrieve an enum from a database and Hibernate doesn't find the property value and therefore throws the following Exception <strong>java.lang.IllegalArgumentException: No enum constant com.intrawa.qx.validator.models.entity.Group.CONFIGTAB.false</strong></p>
  
  <p>The problem occurs when hibernate calls the valueof method of the enum: at java.lang.Enum.valueOf(Enum.java:238)</p>
  
  <p>I'm working with a Database where I cannot change it's column names.</p>
  
  <p>For example look at the code:</p>
  
  <pre><code>@Entity
  @Data
  @Table(name = "bm_host_groups")
  public class Group {
  
      @Enumerated(EnumType.STRING)
      private CONFIGTAB configTab;
  
      @AllArgsConstructor
      private enum CONFIGTAB {
          TRUE("true"),
          FALSE("false");
  
  
          @Getter @Setter
          private String value;
      }
  }
  </code></pre>
  
  <p>The DB has a column called configTab with enum value type and two possible values ("true", "false"), when hibernate call valueof("true") it doesn't find TRUE and throws the exception.</p>
  
  <p>One solution I found it's on this post: <a href="https://stackoverflow.com/questions/12639791/what-is-the-reason-for-java-lang-illegalargumentexception-no-enum-const-class-e">What is the reason for java.lang.IllegalArgumentException: No enum const class even though iterating through values() works just fine?</a></p>
  
  <p>However, it needs a custom method that takes for example "true" as argument from the DB then capitallize it in order to find the value of the enum.</p>
  
  <p>I searched a way to override Enum's valueof() but this post says it's not possible and basically suggest the same as the first solution, make a custom method and make the client calls it. Post: <a href="https://stackoverflow.com/questions/9662170/override-valueof-and-tostring-in-java-enum">Override valueof() and toString() in Java enum</a></p>
  
  <p>Is there a way to make hibernate call a custom method instead of valueof()?</p>