Ciprian
Ciprian

Reputation: 23

JDO enums implementing interface

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?

Upvotes: 2

Views: 603

Answers (1)

DataNucleus
DataNucleus

Reputation: 15577

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

Upvotes: 1

Related Questions