I have an enumerated type field current_status in a table history in a PostgreSQL database. The enumeration is defined as:
CREATE TYPE et_status AS ENUM
('PENDING', 'SUCCESS', 'LATE', 'EARLY', 'FAILED', 'IN_PROGRESS', 'EXPIRED');
I added an enumerated type on the server side and made some changes to the type on the relevant field and the getter and setter. This looks like:
@Entity
@Table(name = "history")
@XmlRootElement
@NamedQueries({ ... })
public class History implements Serializable {
public enum StatusType implements Serializable
{PENDING, SUCCESS, SUCCESS_LATE, SUCCESS_EARLY,
FAILED, IN_PROGRESS, EXPIRED};
...
@Lob
@Column(name = "current_status")
private StatusType currentStatus;
...
public StatusType getCurrentStatus() {
return currentStatus;
}
public void setCurrentStatus(StatusType currentStatus) {
this.currentStatus = currentStatus;
}
}
When testing the web service, I get the following error:
The object [PENDING], of class [class org.postgresql.util.PGobject], from mapping
[org.eclipse.persistence.mappings.DirectToFieldMapping[currentStatus-->history.current_status]]
with descriptor [RelationalDescriptor(entities.History --> [DatabaseTable(history)])],
could not be converted to [class java.lang.Integer].
Searching the Internet yielded this solution, but it appears to require the use of org.hibernate.annotations.TypeDef which I don't seem to have in my installation.
Question: What is the proper method of converting from a PostgreSQL enumerated type into a Java enumerated type via a RESTful Web Service?
Database: PostgreSQL 8.4
App Server: Glassfish 3.1.2.2
IDE: NetBeans 7.2
JDK: 7 update 7