Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: does neo4j support unique index constraint?

  1. #1
    Join Date
    Jun 2011
    Posts
    4

    Default does neo4j support unique index constraint?

    I have an entity which like
    @nodeentity
    user{
    @index string name;
    ...
    }
    I persist two users with same name and success
    after that, Iget exception when i invoke repo.getByPropertyName("name","samename");
    but not get exception when i execute persist
    is it the behavior of neo4j?
    or I do something wrong?

  2. #2
    Join Date
    Jan 2011
    Location
    Dresden, Germany
    Posts
    525

    Default

    Neo4j itself has no such constraint, we thought about adding it to Spring Data Graph though. Right now you have to check for yourself (i.e. do a repository.getByPropertyName() before creating the entity), best done in a

    Code:
    public static User obtain(GraphRepository<User> repo, String name) {
       User user = repo.findByPropertyValue("name",name);
       if (user!=null) return user;
       return new User(name).persist();
    }
    We might add this option in one of the next milestone releases.

    Cheers
    Michael

  3. #3
    Join Date
    Jun 2011
    Posts
    4

    Default

    Yes, and I have to synchronized this method.
    Furthermore, even I synchronized it, I still can not avoid this inconsistent situation in app cluster enviroment.
    It may be the major drawback point of neo4j or graph db likewise.

    Thanks

    Quote Originally Posted by MichaelHunger View Post
    Neo4j itself has no such constraint, we thought about adding it to Spring Data Graph though. Right now you have to check for yourself (i.e. do a repository.getByPropertyName() before creating the entity), best done in a

    Code:
    public static User obtain(GraphRepository<User> repo, String name) {
       User user = repo.findByPropertyValue("name",name);
       if (user!=null) return user;
       return new User(name).persist();
    }
    We might add this option in one of the next milestone releases.

    Cheers
    Michael
    Last edited by stoneboy; Jun 3rd, 2011 at 04:09 AM.

  4. #4

    Default

    Hi,
    Any new development on support for unique constraints? Is that planned for a particular release or not yet?
    Thanks.
    Eugen.

  5. #5
    Join Date
    Jan 2011
    Location
    Dresden, Germany
    Posts
    525

    Default

    Eugen,

    Neo4j itself now added support for unique entities with 1.6. so it will be added to SDN 2.1.

    Michael

  6. #6

    Default

    That's good news indeed.
    Will non-null constraints also be supported?
    Thanks.
    Last edited by eugenparaschiv; Feb 18th, 2012 at 03:48 PM.

  7. #7
    Join Date
    Jan 2011
    Location
    Dresden, Germany
    Posts
    525

    Default

    This should be part of the already existing JSR-303 support, to use @NotNull on a field.

    Doesn't that work for you?

    Michael

  8. #8

    Default

    I have not attempted to use @NotNull, as that is related to validation, not database constraints. I was looking for something simillar to the JPA: @Column( nullable = false ).
    Thanks for the feedback.
    Eugen.

  9. #9
    Join Date
    Jan 2011
    Location
    Dresden, Germany
    Posts
    525

    Default

    There are no null properties in Neo4j they just don't exist then.

    SDN removes properties that are set to null.

    Michael

  10. #10

    Default

    So the null properties are silently ignored before the entity gets persists with Neo4J? In that case, I understand how having a non null constraint may proove problematic, but that still makes working with the API difficult. When I'm persisting an entity, I would want to be able to make sure that certain fields cannot be saved as null, and I would want the persistence layer (Neo4J + SDN) to enforce that. I am aware that this kind of concept is comming from an SQL oriented world, but it is nevertheless a very useful thing to have. The alternative is less optimal (and overly verbose) - I would need to enforce these kinds of checks manually, which, for any sort of nontrivial entity, will lead to a lot of code that could potentially not exist.
    So, perhaps SDN may provide the enforcing before going to Neo4J.
    Thanks for the usefull info.
    Eugen.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •