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.

NodeEntity Relationship binding

Hi,

I'm trying to get the node entity along with relationship using spring data. Relationship values are not being binded when I annotated with '@Relationship' tag.

For Ex., User has list of task linked through task_status. I would like to query the list of pending tasks(task_status).

/** In UserRepository.java **/

match(u:user {email : {0})-[rel:PENDING]-(t:task) return u, rel, t
User getPendingTasks(String email);

/** User Entity **/

@NodeEntity(label="user")
public class User {

	private Long id;
	
	private String email;
	
	@Relationship(type = "PENDING")
	private List<Task> tasks = new ArrayList<>();
	
	...
}

/** Relationship Entity **/

@RelationshipEntity(type = "PENDING")
public class TaskStatus {

	@Id 
	private Long id;
    
	@Property  
	private String status;
    
	@StartNode
    private User user;
	
	@EndNode
	private Task task;
}

/** In Service **/

User user = userRepository.getPendingTasks(email);
return user.getTasks();       //Yields No data

Like JPA entity, will the associated relationship is not being bound??

2 REPLIES 2

Jiropole
Graph Voyager

Does it make any difference if you indicate the directionality, e.g.

@Relationship(type = "PENDING", direction = Relationship.OUTGOING)

What versions of Spring Data Neo4j and Neo4j-OGM do you use in the project?
I am asking because this should work in any version 3.+ of Neo4j-OGM. I just tested this with the same repository method you defined. There are just closing parenthesis and the@Query annotation missing in your example, or is there more in the query?

The direction can be omitted in this case because OUTGOING is the default direction.

Edit: are you also defining the lower-case task for the Task type in your entity definition? Your query does also use a lower-case label for the tasks.