Question

I have an entity Place:

@NodeEntity
@TypeAlias(value="Place")
public class Place  implements Serializable{
    private static final long serialVersionUID = 1L;
    @GraphId 
    private Long nodeId;

    @JsonProperty("id")
    @Indexed(unique=true)
    private String id;

        //...
}

And I try to get a node based on its id attribute this way:

String pfc = "1234";
(Node)template.getIndex(Place.class, "id").get("id", pfc).getSingle()

But I'm having this exception :

java.lang.IllegalStateException: Index name for class java.lang.String id rel: false idx: true must differ from the default name: Place

Must I necessairly add a name to the index? If yes, how should I do for the existent data?

Was it helpful?

Solution

Which version are you using? In SDN 3.x for Neo4j 2.x the indexes and constraints are used automatically.

I would use a PlaceRepository with a findById() method.

Or in general cypher queries that access place like this:

MATCH (p:Place {id:{id}})-->(x)
RETURN x

You can access them manually with template.merge() or template.findByLabelAndProperty() which I would only recommend when you know what you're doing.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top