質問

I'm using Spring Data, Neo4j and Jackson to serve a JSON API. I have a simple User class like this:

@NodeEntity
@JsonAutoDetect(JsonMethod.NONE)
public class User {
    @GraphId Long internalId;
    @Indexed String id;

    public User() {}

    public User(String id) {
        this.id = id;
    }

    @JsonProperty
    public String getId() {
        return this.id;
    }
}

I'm using @Indexed to use the id attribute in the URLs. Is there any possibility to set this field as unique? (as in a RDBMS)

Now I can create many users with the same id:

Neo4jTemplate template;
...
template.save(new User("testid"));
template.save(new User("testid"));

I'd like an exception on the second save or, at least, I'd like to replace the first user in the DB.

Thank you.

役に立ちましたか?

解決

I ask on Stack Overflow. In the same day a new Spring-Data-Neo4j milestone is released... that fixes the DATAGRAPH-181 issue and add support for unique indexes.

Just need to annotate the field like this:

@Indexed(unique=true) 

他のヒント

is it possible to use @GraphId for that?

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top