NodeEntity Relationship binding

(Developer Spring) #1


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 **/

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

/** User Entity **/

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 {

	private Long id;
	private String status;
    private User user;
	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??

(Jiropole) #2

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

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

(Gerrit Meier) #3

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.