是否可以使用列名获取查询结果,而不是使用列注释创建实体?像:
@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();
返回结果只有值,但没有列名。
否则,有没有办法通过Spring JPA获得PostgreSQL row_to_json的结果?
@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();
它将抛出JDBC 111异常。