Neo4j: Create multiple relationships between the same two nodes
In my case, I want to build a addreebook in neo4j, which a person has mutiply cellphones and maybe some cellphones have the same concacter with same phone number but different nicknames. such as
user A has two cellphones C1, C2,
C1 | 18190752225 | wife |
C2 | 18190752225 | 老婆 |
I model this with mutiply relationsips between two nodes.
User A -----(C1,wife)--------------->UserB(18190752225)
\
\
-------(C2,老婆)--------------->UserB(18190752225)
The source codes
@NodeEntity @JsonAutoDetect @JsonIgnoreProperties(ignoreUnknown = true) public class User { private static final Logger logger = Logger.getLogger(User.class.getName()); @Indexed private String userId; @Indexed private String nickname; private String realname; private byte sex; private byte type; // common user or businesses private String tags;// personal tags @Indexed(unique = true) private String cellphone; private String cellphoneID; private byte status; private float credit; private boolean registered; @GraphId private Long nodeId; @Labels private Set<String> lables; @RelatedToVia Set<Knowing> knows;
@RelationshipEntity(type = "knows") public class Knowing { private static final Logger logger = Logger.getLogger(Knowing.class.getName()); @GraphId Long relationshipId; String cellphoneID; String nickName; @StartNode User user; @EndNode User contacter;
user.addKnowing(friendInDB, duser.getCellphoneID(), friend.getNickname());
But this operation can not add the second relationships between UserA and UserB.
After googling, I found
Note
Spring Data Neo4j ensures by default that there is only one relationship of a given type between any two given entities. This can be circumvented by using the createRelationshipBetween() method with the allowDuplicates parameter on repositories or entities.
But, in my codes it doesn't work at all.
Knowing r = template.createRelationshipBetween(user, friendInDB, Knowing.class, "knows", true); r.setCellphoneID(duser.getCellphoneID()); r.setNickName(friend.getNickname()); template.save(r);
Preferences
http://stackoverflow.com/questions/18403802/can-a-node-contain-a-collection-of-relationships-with-the-same-end-node
http://stackoverflow.com/questions/18392393/unable-to-create-more-than-2-same-relations-between-two-nodes
- Informed A* algorithm to find the shortest path between two nodes
- Multiple process create and delete the same name file conflict
- Find the distance between two nodes
- U面经Prepare: Print Binary Tree With No Two Nodes Share The Same Column
- Steps of configuring IDoc to exchange data between two clients of the same SAP system
- freemarker中 The only legal comparisons are between two .. 问题解决
- Pick two points at random from the interior of a unit square, what is the expected distance between them?
- given two directory trees how to find which files are the same?
- two or more web modules defined in the configuration have the same context root解决方案
- 【MongoDB】The connection between two tables
- Route Between Two Nodes in Graph
- Self Summary: Lua Language(two useful links) and the difference between : and .
- [html] PHP使用Google map web services来计算两点间的距离 -- Compute the distance between two place via Google map services in PHP
- Two components with the same id AJAX error
- 2 counts of IllegalAnnotationExceptions Class has two properties of the same name JAXB异常
- Cannot configure two CRS instances on the same cluster
- lintcode-medium-Route Between Two Nodes in Graph
- 【Webservice】2 counts of IllegalAnnotationExceptions Two classes have the same XML type name
- Installing multiple CAB files with the same setup application
- contains multiple state decs of the same type