1

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

1 Answer 1

1

Don't use @Lob, try @Enumerated(EnumType.STRING) instead.

However you have to make sure then that the names in java exactly match those in postgresql (which they don't in your current code).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.