Issue
I made a native query in my repository which only give specific columns as output.
@Query(value = "SELECT installation_id,description,checklist_steps,creation_date,location,status FROM installation_details", nativeQuery = true) List < Object > findCustomInstallation();
But the response I am getting on postman is only showing me the data inside columns so how I can show column name also?
Note:- I am not using my model as it is having one to one mapping of other table also and if I run query using my model it is also showing me data of other table on postman that is why I used Object instead of model.
The response I am getting is this
> { > "status": 1, > "message": "Successfully Fetched", > "myObjectList": [ > [ > 1, > "traffic project", > "13", > "2021-01-30T06:57:34.000+0000", > "Delhi", > 1 > ],
Solution
You can use projections to get this working.
Create an interface with only getters
public interface InstallationDetailsProjection
{
Long getInstallation_id();
String getDescription();
//similar for other fields
}
Then add alias to your native query
@Query(value = "SELECT installation_id as installation_id,description as description //more fields
FROM installation_details", nativeQuery = true) List < InstallationDetailsProjection > findCustomInstallation();
This should solve your issue.
Answered By - Sridhar Patnaik
Answer Checked By - Clifford M. (JavaFixing Volunteer)