jopa icon indicating copy to clipboard operation
jopa copied to clipboard

Sweep cache of instances possibly referencing updated entity

Open ledsoft opened this issue 4 years ago • 0 comments

When an entity is updated (merged into the persistence context) and the transaction is committed, the second level cache updates only the updated entity itself. However, there may be other entities referencing (possibly indirectly) the updated entity. These should be evicted as well.

Consider the following example:

@OWLClass(iri = '...')
class Report {

@OWLObjectProperty (iri = '...')
private Audit audit;
}

@OWLClass(iri = '...')
class Audit {

@OWLObjectProperty (iri = '...')
private Set<AuditFinding> findings;
}

@OWLClass(iri = '...')
class AuditFinding {
}

Now, if a Report of an audit with some findings is loaded into the cache and then a particular AuditFinding is updated directly, the audit (and report transitively) will wrongly reference a stale finding instance. Thus, it should be evicted to prevent subsequent incorrect data reads.

Note that, as can be seen from the example, this sweep should be recursive.

ledsoft avatar Sep 04 '21 15:09 ledsoft