Neo4j: Create multiple relationships between the same two nodes

1 篇文章 0 订阅

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,

C118190752225wife
C218190752225老婆

 

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

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值