Hi All,
We use Hibernate 3.3.1 for our application. For a new enhancement we require to execute Native SQL queries. I also require the column aliases. My code is as below:
Code:
Session session = (Session) getJpaTemplate().getEntityManagerFactory().createEntityManager().getDelegate();
SQLQuery sqlQuery = session.createSQLQuery(query);
List<Object[]> list = (List<Object[]>)sqlQuery.list();
String[] colAliases = sqlQuery.getReturnAliases();
for(int i=0; i<= colAliases.length; i++){
System.out.println(colAliases[i]);
}
But it seems retrieving column aliases is not supported for SQL Queries. The following exception is thrown:
Quote:
java.lang.UnsupportedOperationException: SQL queries do not currently support returning aliases
at org.hibernate.impl.SQLQueryImpl.getReturnAliases(SQLQueryImpl.java:245)
Is there any other way that I can execute a SQL query and retrieve column names via Hibernate ? Or is JDBC the only option?
Thanks,
Midhun