Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
06-16-2021 06:15 AM
We have 2 nodes
@Node("User)
public class User {
@Id
private String id;
private String name;
}
@Node("Post")
public class Post {
@Id
@GeneratedValue(generatorClass = GeneratedValue.UUIDGenerator.class)
private UUID id;
private String text;
private Instant createdAt;
@Relationship(type = "AUTHOR", direction = Relationship.Direction.INCOMING)
private User author;
}
and we are trying to retrieve all the user's posts
@Query(value = "MATCH (author:User)-[:AUTHOR]-(post:Post) RETURN post, author",
countQuery = "MATCH (author:User)-[:AUTHOR]-(post:Post) RETURN count(post)")
Page<PostEntity> findPageByUserId(String userId, Pageable pageable);
We retrieve all the posts, but author is null in the Post
class
How to retrieve also the author?
06-16-2021 06:36 AM
You would also have to return the relationships (to be sure that only the correct types are mapped):
MATCH (author:User)<-[r:AUTHOR]-(post:Post) RETURN post, collect(r), collect(author)
would be the way to go. Please use the collect
s for now, even that this is a 1:1 relationship because the mapping part is a little bit picky. There is already a change but not yet released.
All the sessions of the conference are now available online