gjrwebber / spring-data-gremlin

Spring data gremlin makes it easier to implement Graph based repositories. This module extends Spring Data to allow support for potentially any Graph database that implements the Tinkerpop Blueprints 2.x API.
69 stars 54 forks source link

Add @Query to Entity properties #27

Open gjrwebber opened 9 years ago

gjrwebber commented 9 years ago

It would be nice to be able to add the @Query annotation above a referenced Collection of @Entities and have it fetched when the Object is loaded from the graph.

Eg


@Entity
//@NodeEntity if using Neo4j annotations.
public class Person {

    private String firstName;
    private Location myLocation;
    //... 

    @Query("graph.V().has('firstName', @firstName)")
    private Set<Person> peopleWithSameName;

    @Query(value = "SELECT expand(in('located_at')) FROM (SELECT FROM Location WHERE [latitude,longitude,$spatial] NEAR [@myLocation.latitude,@myLocation.longitude,{\"maxDistance\":0.05f}])", nativeQuery = true)
    private Set<Person> peopleNearMe;

    // ...

}