Sourav
Sourav

Reputation: 21

org.neo4j.ogm.exception.TransactionManagerException: "Transaction is not current for this thread" when the session is used in prototype scope

When using a prototype scoped Session with the @Transactional annotation in SDN 4.1.X, I am seeing the following exception:

org.neo4j.ogm.exception.TransactionManagerException: "Transaction is not current for this thread"

I recently upgraded my Spring Boot project to SDN 4.1.X and Neo4j OGM 2.0.3. It seems that when multiple Sessions are initiated ( due to being prototype scoped ) the DefaultTransactionManager is not able to find the reference for the previously opened transaction during commit.

I see the static ThreadLocal is being removed each time the session is created.

But the same project is working fine with SDN 4.0.0 and OGM 1.1.4 version. So as a work around I have had to make Session thread scoped. Could anybody please clarify what modification made to the SDN/OGM which can cause this. Or this is the expected behaviour in SDN 4.1.X?

Upvotes: 1

Views: 807

Answers (2)

digx1
digx1

Reputation: 1088

OK I think I understand the issues.

Prior to SDN 4.2 / OGM 2.1, Configuration and Transactions were done very differently. Users were required to define and specify a scope on the Session bean in a configuration class that extended Neo4jConfiguration. This led to a lot of confusion amongst developers in terms of which scope to use for their applications. In this latest version, this has been completely done away with. You can see how to upgrade in this blog post. We also won't be supporting this old configuration mechanism going forward.

The new version of SDN will be RC1 toward the end of this month and RELEASE around 12th of December so it won't be SNAPSHOT for too much longer!

The blog post also talks about how Transactions work.

Upvotes: 0

Sourav
Sourav

Reputation: 21

Thanks for the reply.

Let me clarify a bit on the Application scope. My application is asynchronous/concurrent and non blocking in nature facililated by Reactor.

The concurrency is controlled by Reactor-Stream APIs based on Pool based Grouping. Which means that the data is stored in Neo4J through concurrent threads ( workers ) from multiple groups ( thread-pool ) created based on certain application specific grouping context. Within a group the interaction with Neo4J is always sequential.

Accordingly, below are the options which I have considered for the Neo4J Session, (I have used @EnableTransactionManagement in Configuration and @Transactional in the method interacting with Neo4J)

  1. "session" - This can not be used as application ( primarily backend application) does not use Spring-MVC container
  2. "prototype" - Means that there will be new session object intialized for each database hits. This works well with SDN 4.0.0 and OGM 1.x. But with upgraded library it does not work anymore. The session is container managed and not used further beyond transaction boundary
  3. "thread" - This requires explicit registration of the scope. However, the session remains alive though the entire thread lifecycle. This would indeed extend the in memory footprint and should be cleaned/flushed repeatedly in order to maintain data integrity.

I thought of upgrading to SDN 4.2.X as well but the only SNAPSHOTs are available which I am a bit sceptic to proceed with.

Also, I see that when the transaction aspect (@EnableTransactionManagement) is removed, it works fine. But I wonder, whether it is handling transaction properly.

Kind of confused on the transaction management around Neo4J OGM in which the session can not be initialized in Singleton or Session scope? Or What is the preferred work around around such scenarios?

Upvotes: 0

Related Questions