ClassCastException when using a single region name for both entity and query results in Hibernate
Issue
-
Declared a named cacheable query for an entity and specifying the same region name for both the query and the entity.
@NamedQuery(name = "Employee.findAll", query = "SELECT a FROM Employee a", hints = { @QueryHint(name = "org.hibernate.cacheable", value = "true"), @QueryHint(name = "org.hibernate.cacheRegion", value = "custom-region-01") } ) @Cache(usage = CacheConcurrencyStrategy.READ_ONLY, region="custom-region-01")
-
When executing the named query the first time, the exception below is raised:
... java.lang.ClassCastException: org.infinispan.hibernate.cache.v53.impl.DomainDataRegionImpl cannot be cast to org.hibernate.cache.spi.QueryResultsRegion at org.hibernate.cache.internal.EnabledCaching.makeQueryResultsRegionAccess(EnabledCaching.java:491) at org.hibernate.cache.internal.EnabledCaching.getQueryResultsCache(EnabledCaching.java:478) at org.hibernate.loader.Loader.listUsingQueryCache(Loader.java:2515) at org.hibernate.loader.Loader.list(Loader.java:2498) at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:504) at org.hibernate.hql.internal.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:395) at org.hibernate.engine.query.spi.HQLQueryPlan.performList(HQLQueryPlan.java:220) at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1508) at org.hibernate.query.internal.AbstractProducedQuery.doList(AbstractProducedQuery.java:1537) at org.hibernate.query.internal.AbstractProducedQuery.list(AbstractProducedQuery.java:1505) at org.hibernate.query.Query.getResultList(Query.java:132) at org.jboss.as.jpa.container.QueryNonTxInvocationDetacher.getResultList(QueryNonTxInvocationDetacher.java:58)
Environment
- Red Hat JBoss Enterprise Application Platform (EAP) 7.2
- Hibernate 5.3
- Infinispan 9.3
Subscriber exclusive content
A Red Hat subscription provides unlimited access to our knowledgebase, tools, and much more.