Reputation: 7501
I'm mixing spring-data and CXF to create a RESTful endpoint that creates neo4j nodes. My structure is a set Interfaces which define the public facing methods, and my implementations which have several private methods under that are called by my public methods.
My private methods have spring-tx's @Transactional
on them, and when I try to call these from my public methods, I get a org.neo4j.graphdb.NotInTransactionException
. Below is a GitHub project that is setup to show my configuration and you can also run it to see what's wrong:
https://github.com/NicholasAStuart/broken-spring-neo4j-cxf.git
Can anyone help me? I've followed the steps from the documentation on spring-data-neo4j, but I cannot seem to get this working, can anyone help me?
Upvotes: 2
Views: 491
Reputation: 41113
As highlighter on chapter 11.5.6 of spring manual:
Method visibility and @Transactional
When using proxies, you should apply the @Transactional annotation only to methods with public visibility. If you do annotate protected, private or package-visible methods with the @Transactional annotation, no error is raised, but the annotated method does not exhibit the configured transactional settings. Consider the use of AspectJ (see below) if you need to annotate non-public methods.
Upvotes: 0
Reputation: 9579
The @Transactional
annotation does not work on private methods.
From the Spring documentation:
When using proxies, you should apply the @Transactional annotation only to methods with public visibility. If you do annotate protected, private or package-visible methods with the @Transactional annotation, no error is raised, but the annotated method does not exhibit the configured transactional settings. Consider the use of AspectJ (see below) if you need to annotate non-public methods.
You may be able to use the aspectj
mode to enable this behavior on any type of method.
Upvotes: 3