-
Notifications
You must be signed in to change notification settings - Fork 618
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
transactionTemplate is null error when use spring data neo4j with spring data jpa #2931
Comments
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 I got some error related to spring-projects/spring-boot#40895 and I think it's same problem like this spring-projects/spring-boot#41275 My workaround is define a beam |
Update, I found that declare a transactionManager will lead jpa transaction error when call saveAndFlush. spring-data-jpa use 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. |
I think spring data neo4j should fix this issue. 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 spring-projects/spring-boot#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 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 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. |
Thanks for provide the root cause. Any reason to check
Why not just check
|
As title, it's work well with spring data neo4j alone, but fail with spring data jpa.
The text was updated successfully, but these errors were encountered: