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

猜你喜欢

转载自ylzhj02.iteye.com/blog/2216622