Lazy/Eager loading/fetching in Neo4j/Spring-Data

前端 未结 3 823
余生分开走
余生分开走 2020-12-09 04:32

I have a simple setup and encountered a puzzling (at least for me) problem:

I have three pojos which are related to each other:

@NodeEntity
public cl         


        
3条回答
  •  心在旅途
    2020-12-09 05:18

    Found the answer to all the questions myself:

    @Iterable: yes, iterable can be used for readonly

    @load on access: per default nothing is loaded. and automatic lazy loading is not available (at least as far as I can gather)

    For the rest: When I need a relationship I either have to use @Fetch or use the neo4jtemplate.fetch method:

    @NodeEntity
    public class User {
        @GraphId Long nodeId;
        @RelatedTo(type="user", direction = Direction.INCOMING)
        private Iterable worker;
        @Fetch Unit currentUnit;
    
        String name;
    
    }
    
    class GetService {
      @Autowired private Neo4jTemplate template;
    
      public void doSomethingFunction() {
        User u = ....;
        // worker is not avaiable here
    
        template.fetch(u.worker);
        // do something with the worker
      }  
    }
    

提交回复
热议问题