2 Replies Latest reply: Jun 10, 2008 4:44 PM by Greybird-Oracle RSS

    SecondaryIndex does not work when SecondaryKey is added to a subclass

    641917
      When I add new SecondaryKey to an entity class JE makes me update its version number. I can, however, add a SecondaryKey to a persistent subclass without updating entity version. The only thing I have to do is update version of persistent subclass itself. For example, if I have an entity class

      ====
      import com.sleepycat.persist.model.*;
      import java.util.*;

      @Entity
      public class NodeBase
      {
      @PrimaryKey(sequence="NodeId")
      public int id;

      @Override
      public String toString()
      {
      return "node #" + id;
      }
      }
      ====

      and its subclass evolves from

      ====
      import com.sleepycat.persist.model.*;
      import java.util.*;

      @Persistent(version=0)
      public class DerivedNode extends NodeBase
      {
      public Collection<Integer> neighbors = new TreeSet<Integer>();

      @Override
      public String toString()
      {
      return super.toString() + " connected to " + neighbors;
      }
      }
      ====

      to

      ====
      import com.sleepycat.persist.model.*;
      import java.util.*;

      @Persistent(version=1)
      public class DerivedNode extends NodeBase
      {
      @SecondaryKey(relate=Relationship.MANY_TO_MANY,relatedEntity=NodeBase.class)
      public Collection<Integer> neighbors = new TreeSet<Integer>();

      @Override
      public String toString()
      {
      return super.toString() + " connected to " + neighbors;
      }
      }
      ====

      The new index "neighbors" remains empty when I add instances of DerivedNode with non-empty neighbors collection. It will only start working when I update version of NodeBase.

      It seems that all index information is maintained within entity definition, regardless of where indexes are defined in its class hierarchy. JE does not enforce entity version number updates when such indexes are added. Is that done by design?

      I tested this with je-3.2.76 using JDK 1.5 on Windows XP.
        • 1. Re: SecondaryIndex does not work when SecondaryKey is added to a subclass
          Greybird-Oracle
          Hi Stan,

          I don't have a complete resolution for this problem but I wanted to let you know that we're working on it and are able to reproduce it. It is a JE bug -- this behavior is not intentional. I will let you know as soon as we have a full resolution, which should be in the next several days.

          Thanks for reporting this.

          --mark                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           
          • 2. Re: SecondaryIndex does not work when SecondaryKey is added to a subclass
            Greybird-Oracle
            Another update: I have identified the problem internally and confirmed that bumping the version of the Entity class is a safe workaround.

            The fix is still to come, but the workaround is safe.

            --mark