How can I get the current session in a Neo4j SDN @Transactional method? e.g. if I want to run a query that is used only in one place and I do not want to make a separate method for it in a repository.
It seems that a SessionFactory must have a getCurrentSession method, but Neo4j SDN implementation does not provide such a method (See here).
1 Like
Also, this may be necessary if the query is build at run-time and we do not know what exactly the query is so that we put in in an annotation.
1 Like
Hello @shayantest2
If you inject the Session
, it will be aware of an ongoing transaction, i.e.
@Service
public class SomeService {
@Autowired // Though I rather prefer constructor injection, which works, too of course
Session session;
@Transactional
public void doSomething() {
// interact with session. The session is actually
// a proxy that knows about the Spring Transaction
}
}