Instead of creating an entity with column annotation, is it possible to get query result with column name? Like:
@Query(value = "select emp.emp_id, emp_fname, emp_lname, emp_division_id, emp_role_id," +
"(select count(*) from cheers.ch_kudos where kudos_receiver_id = emp.emp_id) as received_kudos_num, " +
"(select count(*) from cheers.ch_kudos where kudos_sender_id = emp.emp_id) as sent_kudos_num " +
"from cheers.ch_employee as emp where emp.emp_active_flag = 'true'",
nativeQuery=true)
List<Object> getAllEmployeesReport();
The return result only has values, but doesn't have column name.
Otherwise, it there a way to get PostgreSQL row_to_json result by Spring JPA?
@Query(value = "select row_to_json(t) from (select emp.emp_id, emp_fname, emp_lname, emp_division_id, emp_role_id," +
"(select count(*) from cheers.ch_kudos where kudos_receiver_id = emp.emp_id) as received_kudos_num, " +
"(select count(*) from cheers.ch_kudos where kudos_sender_id = emp.emp_id) as sent_kudos_num " +
"from cheers.ch_employee as emp where emp.emp_active_flag = 'true') t",
nativeQuery=true)
List<Object> getAllEmployeesReport();
It will throw JDBC 111 exception.