question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Multithreaded use of session.save() results in relationships being wrongly deleted

See original GitHub issue

When 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:closed
  • Created 8 years ago
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
kjkrumcommented, Jul 7, 2016

IMO, this information should be included in the Javadoc for Session.

1reaction
vince-bickerscommented, Mar 3, 2016

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.

   // http-session scope
    @Bean
    @Scope(value = "session", proxyMode = ScopedProxyMode.TARGET_CLASS)
    public Session getSession() throws Exception {
        return super.getSession();
    }
   // http-request scope
    @Bean
    @Scope(value = "request", proxyMode = ScopedProxyMode.TARGET_CLASS)
    public Session getSession() throws Exception {
        return super.getSession();
    }
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found