Can I retrieve column names in a JPA native sql query?

stuff22 picture stuff22 · Apr 14, 2011 · Viewed 8.4k times · Source

Possible Duplicate:
How to get ResultSetMetaData from enity manager?

Given a simple table (example_table) with the following columns: id, first_name, last_name is it possible, by executing a JPA native sql query em.createNativeQuery("select * from example_table") retrieve the column names as well as the data? Running the getResultList() on the query only returns the data. How else can I retrieve the column names?

Answer

Kevin D. picture Kevin D. · Dec 18, 2012

try this

em.unwrap(Session.class).getDescriptor(Currency.class).getFields()