Open abccbaandy opened 2 months ago
Got same error on Spring boot 3.3.1 and 3.3.2
I think this maybe cause of this https://github.com/spring-projects/spring-boot/blob/8ea6d3c92ead011af1e8980272b2e1d8502bab4e/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/neo4j/Neo4jDataAutoConfiguration.java#L113 Neo4jTransactionManager transactionManager
not created.
I got some error related to https://github.com/spring-projects/spring-boot/issues/40895 and I think it's same problem like this https://github.com/spring-projects/spring-boot/issues/41275
My workaround is define a beam Neo4jTransactionManager transactionManager
copy from Neo4jDataAutoConfiguration
Update, I found that declare a transactionManager will lead jpa transaction error when call saveAndFlush.
spring-data-jpa use transactionManager
in JpaBaseConfiguration
, and neo4j`s transactionManager will disable it.
Now I make a neo4jTemplate and new a transactionManager in it, it finally solve this.
@Bean({"neo4jTemplate"})
@ConditionalOnMissingBean({Neo4jOperations.class})
public Neo4jTemplate neo4jTemplate(
Neo4jClient neo4jClient,
Neo4jMappingContext neo4jMappingContext,
Driver driver, DatabaseSelectionProvider databaseNameProvider, ObjectProvider<TransactionManagerCustomizers> optionalCustomizers
) {
Neo4jTransactionManager transactionManager = new Neo4jTransactionManager(driver, databaseNameProvider);
optionalCustomizers.ifAvailable((customizer) -> {
customizer.customize(transactionManager);
});
return new Neo4jTemplate(neo4jClient, neo4jMappingContext, transactionManager);
}
Having two spring data modules in place requires two transaction managers. Your solution is the way to go.
As you have already found out, there was some trouble around the transaction managers after we required it also for the Neo4jTemplate
to be in place. Sorry for the (needed) inconvenience.
If there is still something causing problems, I am happy to help. Otherwise feel free to close this issue.
Having two spring data modules in place requires two transaction managers. Your solution is the way to go. As you have already found out, there was some trouble around the transaction managers after we required it also for the
Neo4jTemplate
to be in place. Sorry for the (needed) inconvenience. If there is still something causing problems, I am happy to help. Otherwise feel free to close this issue.
I think spring data neo4j should fix this issue. To do the autoconfig is the main feature of starter, isn't it? Since I am not "customize" the transaction config, why do I need add those code?
I want to use jpa and neo4j, then I add neo4j starter and jpa starter. Then everything should just work.
hi @meistermeier please see the https://github.com/spring-projects/spring-boot/issues/40953, I think this should be fixed in spring boot project.
And I don't know this project should give the autoconfig thing to spring-boot or spring-boot project do it separate. Whether or not, we can make this better.
I think spring data neo4j should fix this issue. To do the autoconfig is the main feature of starter, isn't it? Since I am not "customize" the transaction config, why do I need add those code?
I understand your ideas and I would be happy to find a solution with the Spring Boot team to make it work. But at the moment, the Neo4jDataAutoConfiguration
will only create a *Neo4j*TransactionManager
if there is no other TransactionManager
already instantiated:
https://github.com/spring-projects/spring-boot/blob/9e3e067a4cbd93bdaf1ed201214e1cbd9b65080e/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/neo4j/Neo4jDataAutoConfiguration.java#L112
This means if the JPA tx manager was created first, there won't be a second one unless it gets defined manually.
Let's keep this open to have a reminder for me to get this sorted out in a clean way. There are some other things around this topic that needs some more testing before I can purpose a solution for this situation.
I think spring data neo4j should fix this issue. To do the autoconfig is the main feature of starter, isn't it? Since I am not "customize" the transaction config, why do I need add those code?
I understand your ideas and I would be happy to find a solution with the Spring Boot team to make it work. But at the moment, the
Neo4jDataAutoConfiguration
will only create a*Neo4j*TransactionManager
if there is no otherTransactionManager
already instantiated: https://github.com/spring-projects/spring-boot/blob/9e3e067a4cbd93bdaf1ed201214e1cbd9b65080e/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/neo4j/Neo4jDataAutoConfiguration.java#L112This means if the JPA tx manager was created first, there won't be a second one unless it gets defined manually.
Let's keep this open to have a reminder for me to get this sorted out in a clean way. There are some other things around this topic that needs some more testing before I can purpose a solution for this situation.
Thanks for provide the root cause.
Any reason to check TransactionManager
?
@ConditionalOnMissingBean(TransactionManager.class)
Why not just check Neo4jTransactionManager
? I think it will be fine with jpa.
@ConditionalOnMissingBean(Neo4jTransactionManager.class)
As title, it's work well with spring data neo4j alone, but fail with spring data jpa.