Search code examples
spring-dataspring-data-jdbc

Spring Data JDBC Interface Projection with nested property


I have this DTOs (data transfer object):

public record ProjectsDto(long id, String projectName, String contact, String fundingCode, LocalDate runtimeFrom,
                          LocalDate runtimeTo, String costUnit, String chapter, String unit, UsersDto users) {
}

and

public record UsersDto(long id, String userName, String firstName, String lastname) {
}

I have this repository:

@Query("select p.id, p.projectname, p.contact, p.funding_code fundingCode, p.runtime_from runtimeFrom, p.runtime_to runtimeTo, " +
            "p.cost_unit costUnit, p.chapter, p.unit, u.id users_id, u.username userName, u.firstname firstName, u.lastname lastName " +
            "from projects p " +
            "inner join users u on u.id = p.users_id " +
            "where p.id = :id")
    Optional<ProjectsDto> findByIdAndProjectTo(long id);

The ProjectDto gets populated with all the simple properties like runtimeTo for example. But the embedded users being a UserDto won´t get populated.

Do i have an error in my repository?


Solution

  • This is simply not supported at the moment.