Skip to content

Instantly share code, notes, and snippets.

@Leward
Last active August 29, 2015 14:23
Show Gist options
  • Save Leward/07f8897b850029a2a8ed to your computer and use it in GitHub Desktop.
Save Leward/07f8897b850029a2a8ed to your computer and use it in GitHub Desktop.
SDN4 Map Object Graph
@NodeEntity
public class User {
@GraphId
private Long id;
private String firstName;
private String lastName;
private String email;
@Relationship(type = "FRIEND", direction = Relationship.INCOMING)
private Set<User> friends;
@Transient
private Long rating;
// ... Getters and Setters ...
}
public interface UserRepository extends GraphRepository<User> {
@Query(
" MATCH (u:User)<-[r:RATES]-() " +
" WHERE id(u) = {id} " +
" WITH u, avg(r1.rating) as rating " +
" (u)-[r:FRIEND*..3]->(u2:User) " +
" RETURN u, rating, r, u2"
)
@ResultMapper(targetKey = "u", customPropeties = {
{"rating", "u.rating"}
})
// Expected result is that the all object graph corresponding the cypher query is populated.
// This would allow to map complex queries and depths using one single Cypher Query
public User getUser(@Param("id") Long id);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment