Hi all,
I am using Spring Data Neo4J 6.1.2 and would like to know if you can apply projections to dynamic relationships to retrieve only fields I am interested in.
Sample of node class:
@Node("Entity")
@Data
public class Entity {
@Id
@GeneratedValue(UUIDStringGenerator.class)
private String id;
....
@Relationship
private Map<String, List<RelatedEntity>> relatedEntities = new HashMap<>();
Sample of relationship class:
@RelationshipProperties
@Data
public class RelatedEntity {
@Id
@GeneratedValue()
private Long id;
@TargetNode
private Entity relEntity;
Repository method: (So I can return different projections)
<T> Optional<T> findById(String id, Class<T> type);
Projection interface
public interface RelatedEntitiesProjection {
Map<String, List<RelatedEntityProjection>> getRelatedEntities();
}
The related entity projection has a few fields I wish to return.
When I run this, all the entity fields are returned. Also the sub relatedEntities are recursively retrieved even though the relatedEntities field is not in the RelatedEntity projection.
{
"relatedEntities": {
"SUPPLIES": [
{
"id": 2,
"relEntity": {
"id": "5ccd6adc-b0ad-4249-93b5-9bc608dbbb0b",
"key": null,
"name": "product1",
"description": null,
"relatedEntities": {} // these are populated when there are related entities
},
"createdBy": null,
"createdDate": null,
"lastModifiedDate": null,
}
],
...
Is there anyway to only return the projection fields for the relationship entities?