Announcement Announcement Module
Collapse
No announcement yet.
does neo4j support unique index constraint? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    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

    Comment


    • #3
      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

      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, 04:09 AM.

      Comment


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

        Comment


        • #5
          Eugen,

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

          Michael

          Comment


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

            Comment


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

              Doesn't that work for you?

              Michael

              Comment


              • #8
                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.

                Comment


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

                  SDN removes properties that are set to null.

                  Michael

                  Comment


                  • #10
                    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.

                    Comment


                    • #11
                      I think this is exactly the case were you would use validation in SDN.

                      Actually SDN explicitly removes properties that are set to null, not just ignores them.

                      Having a schema less database underneath the responsibility for this kind of constraint enforcement is usually moved to the application layer.

                      Michael

                      Comment


                      • #12
                        I see. I will give the validation annotation a try then.
                        Thanks.

                        Comment

                        Working...
                        X