Spring Data for Neo4j supports optimistic locking as described by the following documentation:
https://docs.spring.io/spring-data/neo4j/docs/current/reference/html/#mapping.annotations.version
SDN will increment the @version
property of all connected relationships. This can cause excessive locking due to write propagation along connected relationships.
This may not cause a failure, due to retries succeeding, but it can cause performance degradation due to the locks that are taken on connected relationships.
An example stack trace that indicates this issue is
org.springframework.dao.OptimisticLockingFailureException:
An entity with the required version does not exist.
at org.springframework.data.neo4j.core.Neo4jTemplate.saveRelatedNode(Neo4jTemplate.java:858)
at org.springframework.data.neo4j.core.Neo4jTemplate.lambda$processNestedRelations$27(Neo4jTemplate.java:768)
at org.springframework.data.mapping.model.BasicPersistentEntity.doWithAssociations(BasicPersistentEntity.java:387)
at org.springframework.data.neo4j.core.Neo4jTemplate.processNestedRelations(Neo4jTemplate.java:677)
at org.springframework.data.neo4j.core.Neo4jTemplate.processRelations(Neo4jTemplate.java:662)
at org.springframework.data.neo4j.core.Neo4jTemplate.saveImpl(Neo4jTemplate.java:406)
at org.springframework.data.neo4j.core.Neo4jTemplate.save(Neo4jTemplate.java:321)
at org.springframework.data.neo4j.repository.support.SimpleNeo4jRepository.save(SimpleNeo4jRepository.java:117)
...
The solution to this problem would be to save the entity using a projection. Using projections for persistence is documented on the following link:
https://docs.spring.io/spring-data/neo4j/docs/current/reference/html/#projections.sdn.persistence
Comments
0 comments
Article is closed for comments.