title: Mapping an Enum with JPA
body: <p>I'm trying to map a string stored in the database (ex. ABC1, BCD2) to an enum (ABC_1, BCD_2).</p>
  
  <p>With hibernate I was able to do this with the following hibernate mapping</p>
  
  <pre><code>&lt;typedef name="LinkEnum" class="GenericEnumUserType"&gt;
      &lt;param name="enumClass"&gt;types.LinkEnum&lt;/param&gt;
      &lt;param name="identifierMethod"&gt;value&lt;/param&gt;
      &lt;param name="valueOfMethod"&gt;fromValue&lt;/param&gt;
  &lt;/typedef&gt;
  </code></pre>
  
  <p>and in the LinkEnum</p>
  
  <pre><code>@XmlType(name = "LinkEnum")
  @XmlEnum
  public enum LinkEnum {
  
  @XmlEnumValue("ABC1")
  ABC_1("ABC1"),
  @XmlEnumValue("BCD2")
  BCD_2("BCD2");
  private final String value;
  
  LinkEnum(String v) {
      value = v;
  }
  
  public String value() {
      return value;
  }
  
  public static LinkEnum fromValue(String v) {
      for (LinkeEnum c: LinkEnum.values()) {
          if (c.value.equals(v)) {
              return c;
          }
      }
      throw new IllegalArgumentException(v);
  }
  }
  </code></pre>
  
  <p>In the JPA class, I'm trying to do the same kind of mapping, however it's having a problem mapping the enum still. Is there an equivalent way to do this with JPA?</p>
  
  <pre><code>private LinkEnum link;
  
  @Enumerated(EnumType.STRING)
  @Column(name = "LINK", nullable = false, length = 8)
  public LinkEnum getLink() {
      return this.link;
  }
  </code></pre>