如果我们有一个像这样的公司节点,它使用OWNS关系链接到另一个节点(位置(。
@NodeEntity ("Company")
public class Company {
@Id
@Property
private String companyId;
@Property
private String partyId;
@Relationship (type = "OWNS", direction = Relationship . OUTGOING )
private Set<Location> ownedLocations;
}
自有关系
@RelationshipEntity (type = "OWNS")
public class Owns {
@Property
private String ownsProperty;
@StartNode
private Company company;
@EndNode
private Location location;
}
这是存储库
@Repository
public interface CompanyRepository extends Neo4jRepository<Company, String> {
@Query ("match (c:Company)-[x:OWNS]-(y) where c.partyId = $0 return c,x,y")
Stream<Company> getCompaniesWithRelationsByPartyId(final String partyId);
}
因此,当我运行此查询时,我只得到Company和Location实体,而没有OWNS ownsProperty。如何使用上述存储库获取关系属性?
注意:我不想使用@QueryResult
在此处输入代码
您必须将Owns
关系实体定义为Company
中关系的类型,如以下
@Relationship (type = "OWNS", direction = Relationship . OUTGOING )
private Set<Owns> ownedLocations;