JDO枚举实现接口

时间:2011-11-07 18:27:29

标签: java interface enums jdo

我正在尝试创建一个JDO持久化类,它包含一个实现特定接口的枚举列表。 这是代码:

public interface Column {

}

public enum ColumnType1 implements Column {
    VALUE11, VALUE12
}

public enum ColumnType2 implements Column {
    VALUE21, VALUE22
}

这是持久的课程:

@PersistenceCapable(detachable = "true")
public class ListTable implements Serializable {

    @PrimaryKey
    @Persistent(valueStrategy = IdGeneratorStrategy.UUIDHEX)
    @Column(jdbcType = "VARCHAR", length = 32)
    private String encodedKey;

    // the list of columns that can be displayed in the table
    @Persistent(defaultFetchGroup = "true", nullValue = NullValue.EXCEPTION)
    private List<Column> columns;

    // constructor and getters ...
}

问题是我收到了这个错误:

javax.jdo.JDOUserException: The MetaData for the element class "com.example.shared.model.Column" of the collection field "com.example.shared.model.ListTable.columns" was not found.
at org.datanucleus.jdo.NucleusJDOHelper.getJDOExceptionForNucleusException(NucleusJDOHelper.java:497)
at org.datanucleus.jdo.JDOPersistenceManager.jdoMakePersistent(JDOPersistenceManager.java:671)
at org.datanucleus.jdo.JDOPersistenceManager.makePersistent(JDOPersistenceManager.java:691)

当我试图坚持ListTable时。 您是否有任何建议我可以做些什么来保持实现特定接口的枚举列表?

1 个答案:

答案 0 :(得分:1)

接口的“第二类对象”(SCO)实现不是JDO可持久化类型(参见JDO规范)。接口用于可持久类型(FCO)