Last active
August 29, 2015 14:23
-
-
Save Leward/07f8897b850029a2a8ed to your computer and use it in GitHub Desktop.
SDN4 Map Object Graph
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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 ... | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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