Rest queries return DTO entity does not working

Hello JmixTeam

I’m trying to return a DTO via rest queries, but the postman from the api is returning me an empty array.

<query name="applicants" entity="jb_ApplicantDTO" fetchPlan="key-value">
        <jpql>
            <![CDATA[
            select new com.company.service.restservices.applicant.ApplicantDTO(a.id, a.firstName)
            from jb_Applicant a
        ]]>
        </jpql>
</query>

I have full access role.
I tried it for jb_Applicant and it returns me a list.
I’ve tried everything but it’s not working at all and I’m not getting any errors. 200 code and an empty array

Screenshot 2024-11-20 122921

Hello,

As i wrote in Telegram chat, there is a problem inside Generic REST Jpql Queries:

You need to specify Entity and its fetch plan for query, it will delegates query to DataManager. But right now we can’t map entity to DTO.

Demo

This query causes exception behavior:
image
Exception:
image

Issue

I created an issue in github.

Retrospective:

As i said, in first approximation seens like this caused by Jmix DataManager, but i need more time to R&D, probably will come back with detailed answer.

Possible solutions:

Also, you can check Projection in JPA:

public interface UserProjection {
    String getUsername();
    String getEmail();
}

@Query("SELECT u.username AS username, u.email AS email FROM User u")
List<UserProjection> findAllUserProjections();

Best Regards,
Dmitry