I have an administrative console in my web application that allows an administrator to execute a custom SQL SELECT query in our database.
At the bottom, the application uses Hibernate, but these queries are not HQL, they are pure SQL, so I use Native Query as follows:
protected EntityManager em;
public List<Object[]> execute(String query) {
Query q = em.createNativeQuery(query);
List<Object[]> result = q.getResultList();
return result;
}
This works correctly, but returns data rows without additional information. I would also like to get the column names, so when I print the results back to the user, I can also print the header to show what the various columns are.
Is there any way to do this?
source
share