neo4j / neo4j-ogm

Java Object-Graph Mapping Library for Neo4j
https://neo4j.com/docs/ogm-manual/
Apache License 2.0
333 stars 165 forks source link

Session-bound cache breaks Read Committed Isolation Level #901

Closed nioertel closed 1 year ago

nioertel commented 2 years ago

Setup

Issue

Neo4j's isolation level is Read Committed. If I start a transaction, subsequent MATCH queries within the same transaction may show different results if the data in the database changes in the meantime. OGM behaves differently. As long as there is no write operation from within the same transaction or an active call to session.clear(), it does not reflect changes from the database for entities that have already been loaded before within the same transaction.

Reproduction case:

  1. 3 Threads T1, T2, T3 perform the following operations
  2. T1 starts a transaction, creates an entity and commits the transaction
  3. T2 starts a transaction and reads the entity that was created by T1; T2 keeps its transaction running
  4. T3 starts a transaction, modifies the entity in the DB and commits the transaction
  5. T2 reads the same entity again

-> In step 5. OGM returns the object from its cache and does not realize the entity was changed in the database. I query all people with last name Miller and OGM suddenly presents me people with last name Doe.

michael-simons commented 2 years ago

Hi @nioertel

First of all, your analysis is correct. However, those are the semantics of Neo4j-OGM and we have no plans on changing them.

meistermeier commented 1 year ago

No recent activity. Closing this now.