spring-boot icon indicating copy to clipboard operation
spring-boot copied to clipboard

TransactionalOperator is not configured in Data Neo4j

Open hantsy opened this issue 1 year ago • 4 comments
trafficstars

When upgraded to Spring Boot 3.3.1(from the build log, Spring Boot 3.3.0 worked), I got an exception when running PostRepositoryTest in my Spring Boot neo4j example which demos using Neo4j reactive template.

Check the build stack here: https://github.com/hantsy/spring-reactive-sample/actions/runs/9722916730/job/26837408667

java.lang.NullPointerException: Cannot invoke "org.springframework.transaction.reactive.TransactionalOperator.transactional
(reactor.core.publisher.Mono)" because "this.transactionalOperator" is null

hantsy avatar Jun 29 '24 14:06 hantsy

I suspect this is due to #40953, the forward port of #40895. Can you please try defining a ReactiveNeo4jTransactionManager bean and see if that helps?

wilkinsona avatar Jun 30 '24 07:06 wilkinsona

Add a ReactiveNeo4jTransactionManager bean, and got new exception like this.

java.lang.IllegalStateException: Failed to retrieve PlatformTransactionManager 
for @Transactional test: [DefaultTestContext@54463380 testClass = com.example.demo.PostRepositoryTest, 

hantsy avatar Jun 30 '24 09:06 hantsy

I have to define a ReactiveNeo4jTransactionManager bean and add @Transactional(NOT_SUPPORTED) on the tests to get the test passed(I have no sense of this).

hantsy avatar Jun 30 '24 10:06 hantsy

I suspect this is due to #40953, the forward port of #40895. Can you please try defining a ReactiveNeo4jTransactionManager bean and see if that helps?

In the commit, the ReactiveNeo4jTransactionManager bean definition is removed.

I do not use @Transactional explicitly in my codes, the error is from reactive neo4j template I used here.

hantsy avatar Jun 30 '24 10:06 hantsy

Please see the javadoc for @DataNeo4jTest where it says:

By default, tests annotated with @DataNeo4jTest are transactional with the usual test-related semantics (i.e. rollback by default). This feature is not supported with reactive access so this should be disabled by annotating the test class with @Transactional(propagation = Propagation.NOT_SUPPORTED)

This note has been there since Spring Boot 2.4 and was added in https://github.com/spring-projects/spring-boot/issues/23630. I believe it's still relevant as https://github.com/spring-projects/spring-framework/issues/24226 to which it links is still open.

I suspect that this wasn't actually working properly in 3.3.0, it just wasn't throwing an exception to make the error obvious.

wilkinsona avatar Jul 01 '24 07:07 wilkinsona

I suspect that this wasn't actually working properly in 3.3.0, it just wasn't throwing an exception to make the error obvious.

I am not sure about this. Originally my testing codes were annotated with a @Transactional(propagation = Propagation.NOT_SUPPORTED), but it was commented out at some time.

hantsy avatar Jul 01 '24 12:07 hantsy

Sorry, I'm not sure I understand.

Annotating the test with @Transactional(propagation = Propagation.NOT_SUPPORTED) is what's documented and recommended. If a failure didn't occur when it was commented out then my suspicion is that it still wasn't actually working properly, but it wasn't throwing an exception so it wasn't obvious. You certainly wouldn't have got the transaction management that you may have expected as there's no such support when using a reactive transaction manager.

wilkinsona avatar Jul 05 '24 13:07 wilkinsona

If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.

spring-projects-issues avatar Jul 12 '24 13:07 spring-projects-issues

Closing due to lack of requested feedback. If you would like us to look at this issue, please provide the requested information and we will re-open the issue.

spring-projects-issues avatar Jul 19 '24 13:07 spring-projects-issues