cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Get current session in SDN

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

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