cancel
Showing results for 
Search instead for 
Did you mean: 

Get current session in SDN

shayantest2
Node Clone

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 ACCEPTED SOLUTION

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
    }
}

View solution in original post

2 REPLIES 2

shayantest2
Node Clone

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.

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
    }
}
Nodes 2022
Nodes
NODES 2022, Neo4j Online Education Summit

On November 16 and 17 for 24 hours across all timezones, you’ll learn about best practices for beginners and experts alike.