Skip to content
Advertisement

How to Map a JPA create native query to projections

I am trying to get count from a postgreSQL database using Spring Data JPA createNativeQuery. However, the query is returning null instead of the actual values.

Here is the JPA createNativeQuery statement below:

JavaScript

I need help mapping the “submitted”, “pending” and “totalApplications” instances from my query in a way that returns the result as below.

Result expected is:

JavaScript

Result am getting:

JavaScript

I would appreciate any help.

Advertisement

Answer

I do not know why but I believe SELECT null AS id is causing null record to be fetched.

If you don’t want id to be fetched then you can use projection with custom RowMapper or DTO projection.

See below:

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement