Multithreaded use of session.save() results in relationships being wrongly deleted
See original GitHub issueWhen saving a new entity linked to an existing entity using session.save()
it results in the relationship being first saved and then deleted when multiple threads are executing session.save()
in parallel.
I wrote a test to showcase the issue here.
I’m only saving new nodes and relationships, however I’m seeing a lot of logs indicating deletion:
DEBUG org.neo4j.ogm.context.EntityGraphMapper: 155 - context-del: ($1300)-[null:VIDEO_DESCRIBES_VIDEO_ASSET]->($1296)
that gets translated to
UNWIND {rows} as row MATCH (startNode) WHERE ID(startNode) = row.startNodeId MATCH (endNode) WHERE ID(endNode) = row.endNodeId MATCH (startNode)-[rel:
VIDEO_DESCRIBES_VIDEO_ASSET]->(endNode) DELETE rel
Issue Analytics
- State:
- Created 8 years ago
- Comments:9 (2 by maintainers)
Top Results From Across the Web
How to create a service with multiple threads which all use ...
First, a Hibernate session is not thread-safe: A Session is an inexpensive, non-threadsafe object that should be used once and then discarded ...
Read more >CWE-567: Unsynchronized Access to Shared Data in ... - MITRE
Within servlets, shared static variables are not protected from concurrent access, but servlets are multithreaded. This is a typical ...
Read more >Session Basics — SQLAlchemy 2.0 Documentation
To change the “SET NULL” into a DELETE of a related object's row, use the delete cascade on the relationship() .
Read more >Python Multithreading and Multiprocessing Tutorial
Threading is just one of the many ways concurrent programs can be built. In this article, we will take a look at threading...
Read more >C++ Tutorial: Multi-Threaded Programming - Terminology ...
A thread uses the same address space of a process. A process can have multiple threads. A key difference between processes and threads...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
IMO, this information should be included in the Javadoc for
Session
.In a web context you should override the Session bean in your Configuration class. You can then apply scoping annotation to scope the OGM session either to a client’s HttpSession, or to each individual HttpRequest. For example.