2014-05-11 15 views
0

我有一個實體的地方得到一個節點:如何使用指數

@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; 

     //... 
} 

我試圖讓基於其ID的節點屬性是這樣的:

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

,但我有此例外:

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

我必須要爲索引添加名稱嗎? 如果是,我應該如何處理現有的數據?

回答

1

你使用的是哪個版本?在SDN 3.x中,Neo4j 2.x自動使用索引和約束。

我會使用PlaceRepositoryfindById()方法。

或在訪問的地方這個一般暗號查詢:

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

您可以template.merge()template.findByLabelAndProperty(),當你知道自己在做什麼,我只想建議手動訪問它們。