Announcement Announcement Module
Collapse
No announcement yet.
[neo4j] Unique key constraint: Applies on root node only or the child nodes as well ? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • [neo4j] Unique key constraint: Applies on root node only or the child nodes as well ?

    After doing couple of testing it seems like, Unique field is enforced only in the nodeEntity where it is declared.
    It does not guarantee the other member variables (nodeEntities) of the nodeEntity to be unique.

    For example following are the two NodeEntity classes, where B is used as member variable in A.

    @NodeEntity
    public class B(
    @Indexed(indexName="i1")
    private String m_BName;
    . . .
    }


    @NodeEntity
    public class A(
    @Indexed(indexName="i2", unique=true)
    private String m_AName;
    private Set<B> m_Bs;
    . . .
    }


    Now I do the following
    A a1 = new A("nameA");
    A.persist();
    A a2 = new A("nameA");
    A.persist();

    After executing the above node A does not get created again because of the unique constraint on m_AName field. But it creates a 2nd set of B entities (Set<B> is member variable of A) when persisting A for the second time.
    I saw if I declare one of the fields (e.g., m_BName) be unique in B, another set of B's does not get recreated while calling A.persist() for the second time.

    The behavior I am expecting here, if the main entity (e.g., A) fails to match the unique constraint, then none of the nodes under it (e.g., B) should be created, regardless the any field in the containing objects are unique or not. Should not that be a normal behavior ? Please suggest.

    I also found that SDN supports at most field to be unique. Is there any plan to increase that later ?


    Thanks in advance
    Faisal

  • #2
    It only applies to the current entity (aka index) and a single field, no children involved.

    As Neo4j only offers single field uniqueness it is hard for SDN to offer something else, we could only do that via concatenation of values.

    Comment

    Working...
    X