title: Entity manager @Enumerated(EnumType.STRING) - how can I make it use toString()?
body: <p>The ratings column in the (MySQL) database has type <code>ENUM('G','PG','PG-13','R','NC-17')</code> (notice the dashes). This:</p>
  
  <pre><code>@Entity
  @Table(name = "movies")
  public class Movie implements Serializable {
  
      @Enumerated(EnumType.STRING)
      private Rating rating;
  
      public static enum Rating {
          G("G"), NC_17("NC-17"), R("R"), PG("PG"), PG_13(
                  "PG-13");
  
          private String label;
  
          private Rating(String label) {
              this.label = label;
          }
  
          public String getLabel() {
              return label;
          }
  
          @Override
          public String toString() { // added but still
              return label;
          }
      }
  }
  </code></pre>
  
  <p>causes a <code>Data truncated for column 'rating' at row 1</code> exception for NC_17("NC-17") (and PG_13("PG-13"), works for the other values) -  nevermind the exception should read <code>Data rejected for enum ENUM('G','PG','PG-13','R','NC-17') for column 'rating' at row 1</code>.</p>
  
  <p>This happens because it tries to insert the string NC_17 - I thought that adding <code>toString()</code> as above would fix this but apparently calls <code>rating.name()</code> to produce the string to insert (instead of  <code>rating.toString()</code>).</p>
  
  <p>Are there any workarounds or do I have to change the type of ratings to <code>ENUM('G','PG','PG_13','R','NC_17')</code> in the DB ?</p>
  
  <p>Edit: from the comments - what I ask is why JPA is not calling toString() for an @Enumerated(EnumType.STRING) entity field on update ? So I can't put in the db arbitrary chars ? It seemed like an oversight to me but apparently it is not - so off for mysql</p>