Getting column names from a JPA Native Query

Master_T :

I have an administrative console in my web application that allows an admin to perform a custom SQL SELECT query on our database.

Underneath, the application is using Hibernate, but these queries are not HQL, they're pure SQL, so I'm using a Native Query like this:

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 it only returns the rows of data, with no extra information. What I would like is to also get the column names, so when I print the results back to the user I can also print a header to show what the various columns are.

Is there any way to do this?

Master_T :

After a long time without answers, and based on my own further research, it seems this cannot be done ufortunately.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=438435&siteId=1