|
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.
|