在获取实体neo4j spring

时间:2018-04-10 15:39:02

标签: neo4j spring-data-neo4j

我正在使用spring和spring-neo4j-data,我尝试用实体获取关系。

我有文件实体

@NodeEntity(label="File")
@NoArgsConstructor
public class FileNeo4jEntity {

@Id
@GeneratedValue
@Getter
@Setter
private Long id;

@Getter
@Setter
private String name;

@Getter
@Setter
private String path;

@Getter
@Setter
@Relationship(type = "HAS_PROPERTY",direction = Relationship.INCOMING)
private List<HasPropertyNeo4jRelationEntity> properties;

public void addProperty(HasPropertyNeo4jRelationEntity relation) {
    if (this.properties == null) {
        this.properties = new ArrayList<>();
    }
    this.properties.add(relation);
}

关系实体

@RelationshipEntity(type="HAS_PROPERTY")
@Builder
@NoArgsConstructor
@AllArgsConstructor(access = AccessLevel.PACKAGE)
public class HasPropertyNeo4jRelationEntity {

@Id
@GeneratedValue
private Long relationshipId;

@Getter
@Setter
@StartNode
private FileNeo4jEntity file;

@Getter
@Setter
@EndNode
private PropertyNeo4jEntity property;

@Getter
@Setter
@Property
int value;
}

和财产实体

@AllArgsConstructor(access = AccessLevel.PACKAGE)
@NoArgsConstructor
@NodeEntity(label = "Property")
public class PropertyNeo4jEntity{

@Id
@GeneratedValue
@Getter
@Setter
private Long id;

@Getter
@Setter
@Relationship(type = "HAS_PROPERTY")
List<FileNeo4jEntity> files;

@Getter
@Setter
private String categoryName;

}

当我通过categoryName从存储库获取属性时,我也会获得填充的文件列表。 当我通过Name从存储库获取文件时(实际上并不重要),属性列表始终为null。我甚至喜欢这样的东西,但没有效果

@Query("MATCH (f:File {name: {0} })<-[r:HAS_PROPERTY]-(p) RETURN f,r,p")
FileNeo4jEntity findByNameWithRelations(String name);

当我获取文件实体时,如何获得也填充的属性列表?

0 个答案:

没有答案