gpt4 book ai didi

java - JDO 枚举实现接口(interface)

转载 作者:行者123 更新时间:2023-11-30 11:50:21 25 4
gpt4 key购买 nike

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

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 时。您对我可以做些什么来保留实现特定接口(interface)的枚举列表有什么建议吗?

最佳答案

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

关于java - JDO 枚举实现接口(interface),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8040875/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com