PROBLEM: Need to cache a native query (Hibernate Query Caching) in a stateless DAO EJB. Hibernate 5.3, Jpa 2.1, JavaEE 7.
RESEARCH:
Working example:
getEntityManager().createNativeQuery("SELECT MIN(start_date) FROM report")
.getSingleResult();
Exception example:
getEntityManager().createNativeQuery("SELECT MIN(start_date) FROM report")
.setHint(QueryHints.HINT_CACHEABLE, true)
.getSingleResult(); // IlligalStateException "aliases expected length is 0; actual length is 1".
QUESTION: How to cache a native SQL request?