JDO 枚举实现接口

发布于 2024-12-14 06:52:40 字数 1322 浏览 3 评论 0原文

我正在尝试创建一个 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 时。 您对我能做什么才能持久保存实现特定接口的枚举列表有什么建议吗?

I'm trying to create a JDO persisted class, that contains a List of enums, that implement a specific interface.
Here is the code:

public interface Column {

}

public enum ColumnType1 implements Column {
    VALUE11, VALUE12
}

public enum ColumnType2 implements Column {
    VALUE21, VALUE22
}

And this is the persisted class:

@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 ...
}

The problem is that I'm getting this error:

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)

when I'm trying to persist a ListTable.
Do you have any suggestions of what can I do to be able to persist a List of enumerations, that implement a specific interface?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

゛时过境迁 2024-12-21 06:52:40

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

"Second-Class Object" (SCO) implementation of an interface is not a JDO persistable type (see the JDO spec). Interfaces are for persistable types (FCOs)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文