2016-03-01 567 views
0

我有两个节点用户和帐户,它们之间的关系是任何一种关系。 我的查询是如何在@Relationship中指定多种关系类型

MATCH (u:User)-[r:rel1|rel2|rel3|rel4]->(a:Account) WHERE u.login_id=~('(?i).*'+{fulltextsearch}+'.*') RETURN u as User,r as acronym 

我的用户POJO是

public class User{ 

    @GraphId 
    private Long id;  

    String fulltextsearch; 

    String user_id; 

    String status; 


//@Relationship(type = "rel1", direction= Relationship.OUTGOING) 
    Acronym acronym; 
    public Acronym getAcronym() { 
    return acronym; 
    } 


    private Set<Account> accounts; 

    public User() { 

    } 

    public String getUser_id() { 
    return user_id; 
    } 

    public String getStatus() { 
    return status; 
    } 


    public String getFulltextsearch() { 
    return fulltextsearch; 
    } 


    public Set<Account> getAccounts() { 
    return accounts; 
    } 


    public void setAccounts(Set<Account> accounts) { 
    this.accounts = accounts; 
    } 

    } 

我在与多个relatioships写我的用户POJO困惑。 我可以给@Relatioship与OR的多重关系。

这样@Relationship(type = "rel1 | rel2", direction= Relationship.OUTGOING)

回答

1

不,你不能提供多种关系类型为@Relationship。你将不得不在你的实体独立声明它们:

@Relationship(type = "rel1", direction= Relationship.OUTGOING) 
    Acronym acronymRel1; 

    @Relationship(type = "rel2", direction= Relationship.OUTGOING) 
    Acronym acronymRel2; 

您可以编写自定义查询基于一组关系类型来获取所有缩略语。

0

Luanne。

感谢您的更新。 我的首字母缩略词Pojo for single relationship看起来像这样,效果很好。

@JsonIdentityInfo(generator=JSOGGenerator.class) 
@RelationshipEntity(type = "rel1") 
public class Acronym { 
@GraphId 
Long id; 
String acronym; 

@StartNode 
private User user; 

@EndNode 
private Account account; 

public Acronym() { 
} 

public String getAcronym() { 
    return acronym; 
} 
public User getUser() { 
    return user; 
} 
public Account getAccount() { 
    return account; 
} 
} 

但如何在这里提到的倍数关系。如果在课程开始前我@RelationshipEntity,则值为空,它不是rel1。 请澄清如何继续使用POJO。

相关问题