0

I have a method a in a class A that calls a method b in a class B

@Service
public class A {
    private B classB;
    ...

    @Async
    @Transactional
    public void a() {
        classB.b();
    }
}

@Service
public class B {
    ...

    @Transactional
    public void b() {
        // load some nodes from neo4j db by GraphRepository
    }
}

this is my neo4j configuration

@Override
@Bean
@Scope(value = "prototype", proxyMode = ScopedProxyMode.TARGET_CLASS)    
public Session getSession() throws Exception {
    return super.getSession();
}

According to the Async annotation, I set the scope value to prototype but It doesn't still work.

org.neo4j.ogm.exception.TransactionManagerException: Transaction is not current for this thread at org.neo4j.ogm.session.transaction.DefaultTransactionManager.commit(DefaultTransactionManager.java:100) ~[neo4j-ogm-core-2.0.1.jar:?] at org.neo4j.ogm.transaction.AbstractTransaction.commit(AbstractTransaction.java:83) ~[neo4j-ogm-api-2.0.2.jar:?] at org.neo4j.ogm.drivers.bolt.transaction.BoltTransaction.commit(BoltTransaction.java:80) ~[neo4j-ogm-bolt-driver-2.0.2.jar:?] at org.springframework.data.neo4j.transaction.Neo4jTransactionManager.commit(Neo4jTransactionManager.java:50) ~[spring-data-neo4j-4.1.1.RELEASE.jar:?] at org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:485) ~[spring-tx-4.2.5.RELEASE.jar:4.2.5.RELEASE] at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:291) [spring-tx-4.2.5.RELEASE.jar:4.2.5.RELEASE] at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96) ~[spring-tx-4.2.5.RELEASE.jar:4.2.5.RELEASE] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.2.5.RELEASE.jar:4.2.5.RELEASE] at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:655) ~[spring-aop-4.2.5.RELEASE.jar:4.2.5.RELEASE]

I used the same technique with another project with SDN 4.0.0 and it is work.

Can be a bug in SDN 4.1.1 and Ogm 2.0.3?

aGO
  • 1,263
  • 14
  • 30

1 Answers1

1

Firstly, have you enabled @EnableAsync with your @Configuration class?

Secondly, unless you are using Spring Web-MVC or a spring aware web application you don't need to change the scope behaviour of Session so you can just remove that line.

Lastly, since you are using @Async with @Transactional you will need to make sure you EnableTransactionManagement(proxyTargetClass=true) on your your @Configuration class as well.

If you find that still doesn't fix your problem try upgrading (after doing all of the above) to SDN 4.2.0-SNAPSHOT-BUILD

@Async in Spring

digx1
  • 1,100
  • 5
  • 9