spring-projects / spring-boot

Spring Boot
https://spring.io/projects/spring-boot
Apache License 2.0
73.61k stars 40.32k forks source link

TransactionalOperator is not configured in Data Neo4j #41275

Open hantsy opened 6 days ago

hantsy commented 6 days ago

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
wilkinsona commented 5 days ago

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?

hantsy commented 5 days ago

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 commented 5 days ago

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 commented 5 days ago

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.

wilkinsona commented 4 days ago

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.

hantsy commented 4 days ago

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.

wilkinsona commented 1 hour ago

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.