I am using JPA 2.1 to perform CRUD operations on my DB. I generated entities from a pre-existing DB using JPA Tools -> Generate entities from Tables option. This created a Java entity named Item.
The DB table Item has a column of type enum item_status
which was created as String type in the Java entity. Now I am trying to insert a column into table Item using the following method and got this error
ERROR: column "status" is of type item_status but expression is of type character varying. Hint: You will need to rewrite or cast the expression.
Item_Test_CRUD.java
// Here I am trying to test if I can insert into the DB
@Test
void test_insert_into_db() {
DBConnection conx = new DBConnection(); // here I get the message login successful, so I assume the connection to the DB is okay
Item it = new Item();
it.setStatus("Rework");
it.setUpdatedAt(new Timestamp(System.currentTimeMillis()));
it.setMetadata("{}");
conx.insert(it);
}
// I am using EntityManager to connect to the DB DBConnection.java
public void insert(Object obj) {
this.em.getTransaction().begin();
this.em.persist(obj);
this.em.getTransaction().commit();
}
// Entity generated by the JPA tool Item.java
@Entity
@Table(name="\"Items\"")
@NamedQuery(name="Item.findAll", query="SELECT i FROM Item i")
public class Item implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Convert(converter=UUIDConverter.class)
private String id;
.
.
@Column(name="status")
private String status;
.
.
}
Any idea what mistake I am doing here ?