This discussion is archived
2 Replies Latest reply: Oct 14, 2006 1:22 PM by greybird RSS

Polymorphism and DPL

539599 Newbie
Currently Being Moderated
Hi guys.

Any persistence solution in annotation model for Polymorphism in
sleepycat 3.10?

Here is my example:

interface Credentials {
}


@Entity
class UserPasswordCredentials implements Credentials {
String username;
String password;

....
}


@Entity
class X509Credentials implements Credentials {
...

}


and in persistent manager it should

class CredentialsPersistentManager {
void save(Credentials cs){
bdb.insert(cs);
}


}


How can I achieve this?
Thanks

/Jack
  • 1. Re: Polymorphism and DPL
    539599 Newbie
    Currently Being Moderated
    I tried and the exception is always

    Exception in thread "main" java.lang.IllegalArgumentException: Not an entity class: com.xxx.yyy.Credentials

    /jack
  • 2. Re: Polymorphism and DPL
    greybird Expert
    Currently Being Moderated
    Jack,

    When you add @Entity to a class, that creates a PrimaryIndex that stores all instances of that class separately from all other instances. From your example, I gather that you want to store all credentials in a single PrimaryIndex, is that correct?

    To do that you need a base class -- not an interface -- that all credential classes extend. For example, you could call it AbstractCredential. This is the class that should have the @Entity annotation. And you should pass this class (AbstractCredential.class) to EntityStore.getPrimaryIndex.

    You can have an interface for Credential that is implemented by AbstractCredential. But the @Entity class must be a class not an interface.

    Then each of the subclasses, UserPasswordCredentials, etc, can extend AbstractCredential. These subclasses should be annotated with @Persistent.

    Mark