spring-data-neo4j using projections with records

37 Views Asked by At

I am trying to project the result of a query in neo4j to a record DTO but i'm getting null in the result without an exception or warning.

The projection works fine for one field in the DTO but the other record implements an interface and failes.

Here is an example

@Node
public record TestNodeA(Long value){}

@Node
public interface ITestNode {
   String name();
}
@Node
public record TestNodeB(String name) implements ITestNode {}
public record ProjectionResult(TestNodeA testNodeA, ITestNode iTestNode){
}
public interface TestEntityRepository extends Neo4JRepository<TestNodeA> {
  @Query(
"""
MATCH (a:TestNodeA) <-- (b:ITestNode)
RETURN a as testNodeA, b as iTestNode
""")
  List<ProjectionResult> getProjectionDataQuery();
}

In the return I do get a value for TestNodeA but I get null for TesteNodeB

If change the Nodes from records to classes and change TestNodeB to Extend another class the projection does work.

0

There are 0 best solutions below