Oct 21st, 2012, 11:11 PM
[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.
public class B(
private String m_BName;
. . .
public class A(
private String m_AName;
private Set<B> m_Bs;
. . .
Now I do the following
A a1 = new A("nameA");
A a2 = new A("nameA");
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