2 Replies Latest reply on Jan 24, 2009 2:02 AM by Greybird-Oracle

    Bug: SecondaryKey "name" attribute, cannot open DB after closing


      I would like to report the following issue (version 3.3.74). Let us assume the MANY_TO_MANY Author-Book relation:

      public class AuthorEntity {
      bq. @PrimaryKey(sequence="authorSeq") \\ private long authorId;
      bq. @SecondaryKey(relate = MANY_TO_MANY, relatedEntity = BookEntity.class, name = "bookId", onRelatedEntityDelete = DeleteAction.NULLIFY) \\ private Set<Long> bookIds;
      bq. ...

      public class BookEntity {
      bq. @PrimaryKey(sequence="bookSeq") \\ private long bookId;
      bq. ...

      I wanted to name the variable "bookIds", not the "bookId" in the AuthorEntity (no major reasons). To achieve this, I have used the "name" attribute of SecondaryKey to point the appopriate member of BookEntity. The Javadoc documentation of SecondaryKey class states:
      public abstract String name

      Specifies the name of the key in order to use a name that is different than the field name.

      This is convenient when prefixes or suffices are used on field names. For example:

      +class Person {+
      bq. +     @SecondaryKey(relate=MANY_TO_ONE, relatedEntity=Person.class, name="parentSsn")+ \\ +     String m_parentSsn;+

      It can also be used to uniquely name a key when multiple secondary keys for a single entity class have the same field name. For example, an entity class and its subclass may both have a field named 'date', and both fields are used as secondary keys. The name property can be specified for one or both fields to give each key a unique name.

      When I create the Environment for the first time, populate it with sample data, and try to add, find, remove the SecondaryKey works as it should. The appropriate id is being nullified. When I close the EntityStore, no error occurs. As I try to open it again I got the NullPionterException from checkSecKeyMetadata:
      Caused by: java.lang.NullPointerException
      bq. +     at com.sleepycat.persist.impl.ComplexFormat.checkSecKeyMetadata(ComplexFormat.java:1143)+ \\ +     at com.sleepycat.persist.impl.ComplexFormat.evolveFieldList(ComplexFormat.java:1428)+ \\ +     at com.sleepycat.persist.impl.ComplexFormat.evolveAllFields(ComplexFormat.java:1245)+ \\ +     at com.sleepycat.persist.impl.ComplexFormat.evolve(ComplexFormat.java:1019)+ \\ +     at com.sleepycat.persist.impl.Evolver.evolveFormatInternal(Evolver.java:440)+ \\ +     at com.sleepycat.persist.impl.Evolver.evolveFormat(Evolver.java:248)+ \\ +     at com.sleepycat.persist.impl.PersistCatalog.<init>(PersistCatalog.java:357)+ \\ +     at com.sleepycat.persist.impl.Store.<init>(Store.java:180)+ \\ +     at com.sleepycat.persist.EntityStore.<init>(EntityStore.java:165)+
      I have tried to check the database with DBVerify, and everything was fine.

      Lukasz Antoniak
        • 1. Re: Bug: SecondaryKey "name" attribute, cannot open DB after closing
          Hi Lukasz,

          Thank you very much for this bug report. You gave us exactly the information we needed and we have been able to reproduce the bug.

          Note that if you enable assertions (-ea) you'll see an assertion fire earlier than the NPE is throw. For example:
          at com.sleepycat.persist.impl.ComplexFormat.evolveFieldList(ComplexFormat.java:1327)
          at com.sleepycat.persist.impl.ComplexFormat.evolveAllFields(ComplexFormat.java:1245)
          at com.sleepycat.persist.impl.ComplexFormat.evolve(ComplexFormat.java:1019)
          at com.sleepycat.persist.impl.Evolver.evolveFormatInternal(Evolver.java:440)
          at com.sleepycat.persist.impl.Evolver.evolveFormat(Evolver.java:248)
          at com.sleepycat.persist.impl.PersistCatalog.<init>(PersistCatalog.java:357)
          at com.sleepycat.persist.impl.Store.<init>(Store.java:180)
          at com.sleepycat.persist.EntityStore.<init>(EntityStore.java:165)
          I'll post back here when this is fixed and we know the exact scope of the problem.

          A workaround for this problem is to remove the name property from the SecondaryKey annotation, as you probably already know.

          Thanks again,
          • 2. Re: Bug: SecondaryKey "name" attribute, cannot open DB after closing
            The fix for this bug will be in the next major release of JE. For reference, the ticket is 16819. Since there is a workaround (don't override the key name), we won't be putting this fix into a JE 3.3 patch release.

            Thanks again, Lukasz, for your clear bug report.