Can anyone exmplain the difference betwen @GraphId and @Index annotation from org.neo4j.ogm.annotation ?
For now, after reading the docs it seems that @GraphId is used to create identifier for Neo4j internal logic and users should not rely on that, because it can be reused over time. But what about @Index?
As I understand, the main advantage of graph based databases is that once we know the node/relation from which to start things become easy, since all we need to do is just traverse the graph from that starting node. And indexing helps to do so, right? So, we can write something like START n = node:index_name(property_name = value) and immitiately start exloring the graph from the indexed node by 'property_name' property, right?
So, consider this entity :
@ToString
@NodeEntity(label = "Event")
@NoArgsConstructor
public class Event{
public Event(String eventName, LocalDate dateTime){
this.name = eventName;
this.date = dateTime;
}
public Event(Long id, String eventName, LocalDate dateTime){
this(eventName, dateTime);
this.id = id;
}
@Getter
@GraphId
private Long id;
@Getter
@Index(unique = true, primary = true)
@Property(name = "name")
private String name;
@Getter
@Property(name = "date")
@Convert(DateConverter.class)
private LocalDate date;
}
As you can see the String name property is annotated with @Index. How can I write Cypher query to actually start from the node with name = 'something'? What is the index name? Or does Spring Data Neo4j 4.2.0.RELEASE figure it itself when write just MATCH (event:Event {name = 'somehting'} ... ?
@Repository
public interface EventRepository extends Neo4jRepository<Event, String>{
Event findOne(String eventName);
}
Here the repositry class and as you might see I am using String as the type of the id of the entity the repository manages, so I assume Spring uses name property of Event class to generate a query for Event findOne(String eventName);