2 Replies Latest reply: Oct 14, 2006 3:22 PM by Greybird-Oracle RSS

    Polymorphism and DPL

      Hi guys.

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

      Here is my example:

      interface Credentials {

      class UserPasswordCredentials implements Credentials {
      String username;
      String password;


      class X509Credentials implements Credentials {


      and in persistent manager it should

      class CredentialsPersistentManager {
      void save(Credentials cs){


      How can I achieve this?

        • 1. Re: Polymorphism and DPL
          I tried and the exception is always

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

          • 2. Re: Polymorphism and DPL

            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.