title: OpenJPA: How to persist entity with enumeration?
body: <p>I have an entity</p>
  
  <pre><code>@Entity
  @Table(name = "product")
  public class Product {
  
      @Id
      private Long id;
  
      @Column(name = "name")
      private String name;
  
      @Column(name = "condition")
      @Enumerated(value = EnumType.STRING)
      private Condition condition;
  
      public enum Condition {
          NEW, USED
      }
      // default constructor and getters/setters omitted
  }
  </code></pre>
  
  <p>And Java code which persists an entity</p>
  
  <pre><code>Product product = new Product();
  product.setItemName("Gloves");
  product.setCondition(Product.Condition.NEW);
  
  entityManager.getTransaction().begin();
  entityManager.persist(product);
  entityManager.getTransaction().commit();
  entityManager.close();
  </code></pre>
  
  <p>Here is my PostgreSQL db.</p>
  
  <p>Enum type.</p>
  
  <pre><code>CREATE TYPE product_condition AS ENUM ('NEW', 'USED');
  </code></pre>
  
  <p>And table.    </p>
  
  <pre><code>CREATE TABLE product (
  id     SERIAL            NOT NULL,
  name   VARCHAR(255)      NOT NULL,
  condition product_condition NOT NULL,
  CONSTRAINT product_pk PRIMARY KEY (id)
  );
  </code></pre>
  
  <p>But cannot insert a new Product into the DB because of</p>
  
  <pre><code>Caused by: org.apache.openjpa.lib.jdbc.ReportingSQLException: ERROR: column "condition" is of type product_condition but expression is of type character varying
    Hint: You will need to rewrite or cast the expression.
    Position: 55 {prepstmnt 1419086773 INSERT INTO product (id, condition, name) VALUES (?, ?, ?)} [code=0, state=42804]
  </code></pre>
  
  <p>How can I fix it?</p>