1

Using neo4j-ogm, I've written the following code, which contains two database calls. I would like it to only have one database call.

public Member loadMemberByDomainSpecificId(String domainSpecificId) {
        String query = "match (m:Member {domainSpecificId: {domainSpecificId}}) return m;";
        Map<String, String> parameters = new HashMap<String, String>();
        parameters.put("domainSpecificId", domainSpecificId);
        Session neo4jSession = Neo4jSessionFactory.getInstance().getNeo4jSession();
        Member member = neo4jSession.queryForObject(Member.class, query, parameters);
        return super.find(member);
}

The first database call is

  1. neo4jSession.queryForObject(Member.class, query, parameters);

The second database call is

  1. return (Member)super(find(member);

super is return session.load(Member.class, member.getId(), 1);

where session is a neo4jSession.

I make the second API call because the first API call fetches only the node / object, and none of its related nodes / objects. The second API call refreshes the node and all its relationships.

Does anyone know how I can efficiently do all of this with only one database call?

queryForObject does not seem to support variable depth as many of the other neo4jSession methods do.

1 Answer 1

3

Almost all of the Neo4jSession operations take filters as formal arguments.

Filters allow you to select objects of a specified type (label) on one or more properties you're interested in matching. These operations return all matched nodes from the filter, along with their their related nodes, to the depth you specify (default depth = 1). So:

Collection<Member> members = session.loadAll(Member.class, new Filters().add("domainSpecificId", domainSpecificId))

should do what you need I think.

Sign up to request clarification or add additional context in comments.

1 Comment

Worked like a charm. Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.