PostgreSQLデータベースcurrent_status
のテーブルに列挙型フィールドがあります。history
列挙は次のように定義されます。
CREATE TYPE et_status AS ENUM
('PENDING', 'SUCCESS', 'LATE', 'EARLY', 'FAILED', 'IN_PROGRESS', 'EXPIRED');
サーバー側で列挙型を追加し、関連するフィールドとゲッターとセッターのタイプにいくつかの変更を加えました。これは次のようになります。
@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;
}
}
Webサービスをテストすると、次のエラーが発生します。
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].
インターネットを検索するとこの解決策が得られましたが、インストールに含まれていないように見えるorg.hibernate.annotations.TypeDefを使用する必要があるようです。
質問:RESTful Webサービスを介してPostgreSQL列挙型からJava列挙型に変換する適切な方法は何ですか?
データベース:PostgreSQL 8.4
アプリケーションサーバー:Glassfish 3.1.2.2
IDE:NetBeans 7.2
JDK:7アップデート7