How to map nested projections with native query

948 Views Asked by At

I want to map my query result to RequestProjection interface values. The following code works and return request id and submission date.

I need to return worker name too. I have tried r.worker_name AS workerName and r.worker_name AS worker_name and r.worker_name AS worker.name but none of them works.

How can I select and map worker name?

Query:

SELECT r.id AS id, r.submission_date AS submissionDate
From Request r
WHERE r.id = 1

Projection:

public interface RequestProjection {

    Long getId();

    Long getSubmissionDate();

    Worker getWorker();

    interface Worker {

        String getName();
    }
}
1

There are 1 best solutions below

0
DarkFeud On

You can do this without native query using the constructor expression, read more here Spring JPA native query with Projection gives "ConverterNotFoundException"