Neo4j OGM图表会覆盖事务中的更改

时间:2015-10-07 14:03:52

标签: java neo4j spring-data-neo4j spring-data-neo4j-4 neo4j-ogm

我们觉得我们终于对我们在neo4j-ogm中看到的奇怪行为有了解释。我们最初认为它与equals / hashcode实现有关,但事实并非如此。

似乎ogm保留了图的缓存副本,并且在事务中所有检索都指向同一个内存对象。

我们创建了一个单元测试来演示行为(下面是一些无效的伪代码)

//all within the same transactional


//retrieve an object from the database

NodeObject no1 = repository.loadObject();


//update some values on the object

no1.setValue("whatever");


//retrieve the same database object into a new java object

NodeObject no2 = repository.loadObject();


//at this point no2 and no1 are the same java object, and any value changes to no1 have been reverted to no2, as is in the database.

这对我们来说似乎是个问题。

我们之前已经观察到这一点,并通过更改检索到的对象的深度(以防止它们的图形在内存中恢复内容)来消除它,但是当它不使用我们的密码查询时,它的可自定义性较低。

请告诉我们如何避免此问题!

1 个答案:

答案 0 :(得分:0)

您可以在bean配置或会话配置中配置该“缓存”的范围,如果它应该通过请求,http-session或应用程序作用域(永远)。

请参阅:http://docs.spring.io/spring-data/neo4j/docs/4.0.0.RELEASE/reference/html/#_session_bean