从JPA Native Query获取列名
我的Web应用程序中有一个管理控制台,允许管理员在我们的数据库上执行自定义SQL SELECT查询。
I have an administrative console in my web application that allows an admin to perform a custom SQL SELECT query on our database.
在下面,应用程序正在使用Hibernate,但这些查询不是HQL,它们是纯SQL,所以我使用这样的Native Query:
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?
经过很长一段时间没有答案,并根据我自己的进一步研究,它似乎无法做到这一点。
After a long time without answers, and based on my own further research, it seems this cannot be done ufortunately.