putNoOverwrite dirties a secondary index
690755Nov 6 2009 — edited Nov 10 2009Context: BDB v4.7.25, DPL through the Java API, replication subsystem enabled (thus with transactions, logging, etc.)
I encounter a strange behavior using putNoOverwrite on an existing entity with secondary keys.
One of the two secondary indexes declared in the entity gets broken.
Let me explain the case with an example.
The entity :
@Entity(version=0)
public class SomeEntity
{
@PrimaryKey
private int pk;
@SecondaryKey(relate=Relationship.MANY_TO_ONE, relatedEntity=AnotherEntity.class, onRelatedEntityDelete=DeleteAction.ABORT)
private int fk;
@SecondaryKey(relate=Relationship.MANY_TO_ONE)
private String state = "UNKNOWN";
}
The first put or putNoOverwrite is perfect:
putNoOverwrite(pk = 1, fk = 10, state = "OK")
My entity is present in DB, I can retrieve it through the secondary database "state" with the value "OK" (method SecondaryIndex.subIndex).
Then the faulty putNoOverwrite:
putNoOverwrite(pk = 1, fk = 10, state = "UNKNOWN")
This call should have no effect. In turn, my entity is still present in DB, and when I retrieve through is PK, I get it untouched.
But when I retrieve it through the secondary index "state" with value "OK" (method SecondaryIndex.subIndex), there is no match. The only secondary key present in the secondary index is "UNKNOWN".
I encounter this issue repeatedly.
Thanks for your help