[英]Neo4j return issue: How to map the properties of one node and one property from other node which connected into java object
我在映射从Neo4j返回到Java的属性时遇到一些问题。
我有两个连接的节点,组(g)和租户(t),返回的值是g,t.id。
在Java方面,我有一个group对象,但它仅映射组而不映射tenantId。
在组对象中,tenantId的类型很长,如果我将其更改为承租人对象并返回具有其关系的完整承租人,它也会映射承租人,但是我希望组将仅包含id而不包含整个承租人。
@NodeEntity(label = "Group")
public class GroupEntity extends AbstractBaseEntity {
public static final String ENTITY_TYPE = "Group";
@Property(name="name")
private String name;
@Property(name="description")
private String description;
@Relationship(type = "MEMBER_OF")
private long tenantId;
}
//The query
@Query("MATCH (g:Group) where g.id = {groupId} " +
"optional match (g)-[:MEMBER_OF]->(t:Tenant) " +
"return g,t.id as tenantId")
Optional<GroupEntity> findById(Long groupId);
它不是那样工作的。
您在实体之间进行映射。
但是对于查询,您可以返回任何形状的数据并将其映射到代表您需求的DTO。
例如
@Query("MATCH (g:Group) where g.id = {groupId} " +
"optional match (g)-[:MEMBER_OF]->(t:Tenant) " +
"return g, collect(t.id) as tenantIds")
Optional<GroupWithTenantIds> findById(Long groupId);
@QueryResult
static class GroupWithTenantIds {
Group group;
Set<Long> tenantIds;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.