I'm migrating an application from Hibernate 4.x to Hibernate 5.3.6. The application has queries like this:
SQLQuery query = getSession().createSQLQuery("SELECT a.a, a.b, a.c FROM aTable");
As the method createSQLQuery has been deprecated, I first replaced the method call with the alternative suggested in the Hibernate Javadoc, namely using createNativeQuery:
NativeQuery query = getSession().createNativeQuery("SELECT a.a, a.b, a.c FROM aTable");
The problem with this is that it produces a compiler warning "NativeQuery is a raw type. References to generic type NativeQuery should be parameterized". Furthermore, of course I'd like to benefit from typed queries, now that they are available. So I changed the query to
NativeQuery<Object[]> query = getSession().createNativeQuery("SELECT a.a, a.b, a.c FROM aTable", Object[].class);
Now the problem is that executing the query with
List<Object[]> retList = query.list();
produces the error
javax.persistence.PersistenceException: org.hibernate.MappingException: Unknown entity: [Ljava.lang.Object;
Researching the problem seems to indicate that it is not possible to use non-mapped entities when using typed native queries (which seems like a serious and unnecessary restriction, but I digress here).
The question: is there any way to execute a native SQL query returning an array of Objects using Hibernate without producing compiler warnings while achieving type safety? If not, is there any sensible alternative?