Announcement Announcement Module
Collapse
No announcement yet.
findAll method in Spring Data Neo4j returns more results than expected. Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • findAll method in Spring Data Neo4j returns more results than expected.

    Hello I am using Spring Data Neo4j 2.1.0 and what I am trying is to insert data by using low level API (using Node and Relationship) and then retrieving by using Spring Data Neo4j. Let me show you the code:

    Code:
            @Autowired
    	private MemberRepository memberRepository;
    	@Autowired
    	private StarshipRepository starshipRepository;
    
    	@Autowired
    	private GraphDatabaseService graphDatabaseService;
    
            public void test_native_insert() {
    
    		/*
    		 * <graph id="G" edgedefault="directed"> <node id="0"></node> <node
    		 * id="1"> <data
    		 * key="__type__">com.lordofthejars.nosqlunit.springdata.neo4j.Member
    		 * </data> <data key="name">Jean-Luc Picard</data> </node> <node id="2">
    		 * <data
    		 * key="__type__">com.lordofthejars.nosqlunit.springdata.neo4j.Starship
    		 * </data> <data key="starship">NCC-1701-E</data> </node> <edge id="0"
    		 * source="1" target="2" label="assignedStarship"></edge> </graph>
    		 */
    
    		Transaction tx = graphDatabaseService.beginTx();
    
    		try {
    			
    			Node jeanLuc = graphDatabaseService.createNode();
    			jeanLuc.setProperty("__type__",
    					"com.lordofthejars.nosqlunit.springdata.neo4j.Member");
    			jeanLuc.setProperty("name", "Jean-Luc Picard");
    
    			System.out.println("Node Id "+jeanLuc.getId());
    
    			Node enterprise = graphDatabaseService.createNode();
    			enterprise.setProperty("__type__",
    					"com.lordofthejars.nosqlunit.springdata.neo4j.Starship");
    			enterprise.setProperty("starship", "NCC-1701-E");
    
    			System.out.println("Node Id "+enterprise.getId());
    			
    			Relationship relationship = jeanLuc.createRelationshipTo(enterprise,
    					DynamicRelationshipType.withName("assignedStarship"));
    			
    			System.out.println("Rel Id "+relationship.getId());
    			
    			tx.success();
    			
    		} finally {
    			tx.finish();
    		}
    
    		loadFromSpringData();
    		
    	}
    
            private void loadFromSpringData() {
    		EndResult<Member> allMembers = memberRepository.findAll();
    
    		Iterator<Member> iterator = allMembers.iterator();
    		System.out.println("+");
    		while (iterator.hasNext()) {
    			Member member = iterator.next();
    
    			System.out.println("M "+member.getName());
    
    			Starship assignedStarship = starshipRepository.findOne(member
    					.getAssignedStarship().nodeId);
    			System.out.println("S "+assignedStarship.getStarship());
    		}
    	}
    When I tun this test findAll method returns two results, one with a member and another one with a null. I have only inserted one Node with type Member so I think it should return only one member. I am sure I am missing something but I don't know what.

    Thank you very much for your help.
Working...
X