Precondition: We have an entity class annotated with NaturalIdCache and the choosen strategy is CacheConcurrencyStrategy.READ_WRITE.
When persisting & deleting such an entity object within the same transaction, after the commit we remain with an obsolete cache entry (key=<naturalid-value> value=<primary key>) If we now create another persistent object with the same naturalId value, this cannot be resolved anymore from shared cache anymore because the cache entry points to an obsolete (deleted) primary key.
{noformat} scope.inTransaction( (session) -> { AllCached it = new AllCached( "it" ); session.persist(it); session.remove(it); } );
// now recreate with same naturarId naturalId value scope.inTransaction( (session) -> { AllCached it = new AllCached( "it" ); session.persist(it); } );
scope.inTransaction( (session) -> { final AllCached shouldBeThere = session.bySimpleNaturalId( AllCached.class ).load( "it" ); assertNotNull( shouldBeThere ); // FAILS!!!! } );
{noformat}
For more informations please see upcoming Pullrequest which will contain a testcase and a fix proposal. |
|