1

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.

Neil Stockton
  • 11,383
  • 3
  • 34
  • 29
TommyQu
  • 509
  • 5
  • 18
  • JDBC 111 exception? Please be more specific. A stack trace would help. – Philipp Merkle Feb 17 '17 at 21:03
  • Perhaps you could consider the answers in [this question](http://stackoverflow.com/questions/15974474/mapping-postgresql-json-column-to-hibernate-value-type) – Viorel Feb 17 '17 at 21:12

0 Answers0