cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Class based projection (DTO)

Given nodes (a:NodeA)-[r:hasCapability]->(b:NodeB) can a DTO class based projection use classes to describe NodeA and NodeB or must the DTO class be a single class and only contain primitive types when using a custom @Query?

public class NodeA {

   @Id @GeneratedValue
   private Long id;

   String name;
   String alias;

   @Relationship(type = "hasCapability", direction = Direction.OUTGOING)
   private List<HasCapability> hasCapabiltyList = new ArrayList<>();
}

public class NodeB {

   @Id @GeneratedValue
   Long id;

   String capability;

   @Relationship(type = "hasCapability", direction = Direction.Incoming)
   private List<HasCapability> hasCapabilityList = new ArrayList<>();
}

@RelationshipProperties
public class HasCapaiblity {

   @Id @GeneratedValue
   Long id;

   @TargetNode 
   NodeB nodeB;
}

Custom query to return all A and B nodes

@Query(" " +
           "MATCH (a:NodeA)-[r:hasCapibilty]->(b:NodeB) " +
           "RETURN   a AS nodeA ,  b AS nodeB  "
           )
   List<NodeDTO> findMessageTest(Long compendiumId);

Should I expect this class projection DTO work? Would the custom query projection know how to map the parameters of node A and node B?

public class NodeDTO {
   NodeADTO nodeA;
   NodeBDTO nodeB;
}

public class NodeADTO {
    String name;
    String alias;
}

public class NodeBDTO {
    String capability
}

1 REPLY 1

I did notice I misspelled "capability" in a couple of locations. I don't think this matters - I'm asking about the concept in general. I don't see a way to go back and edit my information I posted.