omnifaces / omnipersistence

Utilities for JPA, JDBC and DataSources
Other
31 stars 12 forks source link

Hibernate cache region name can exceed maximum of 255 bytes #22

Closed Edubits closed 6 years ago

Edubits commented 6 years ago

Hibernate/Infinispan uses a ByteString internally as identifier for caches, the maximum length is 255 bytes. page.toString() can result in longer Strings when for example some filters are added. Would it be possible to make the region name less fine-grained? (the region is not the identifier for a specific cache entry, but more a grouping of related entries, so I assume it shouldn't be an issue)

BalusC commented 6 years ago

It's now set to name of the result type.

https://github.com/omnifaces/omnipersistence/commit/bd79998675cde4583aa32e9bfe5d1564c7cdb2a6#diff-b95bff2acfb93244986448a03cee7a57R1258

Edubits commented 6 years ago

Using the name of the result type is the same strategy as used by Hibernate internally. When you get a page with a result type of an Entity the used region will overlap with an internal cache causing the following exception:

Exception level 1: 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:221)
    at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1508)
    at org.hibernate.query.internal.AbstractProducedQuery.doList(AbstractProducedQuery.java:1538)
    at org.hibernate.query.internal.AbstractProducedQuery.list(AbstractProducedQuery.java:1506)
    at org.hibernate.query.Query.getResultList(Query.java:146)
    at org.hibernate.query.criteria.internal.compile.CriteriaQueryTypeQueryAdapter.getResultList(CriteriaQueryTypeQueryAdapter.java:73)
    at org.omnifaces.persistence.service.BaseEntityService.executeQuery(BaseEntityService.java:1712)
    at org.omnifaces.persistence.service.BaseEntityService.getPage(BaseEntityService.java:1633)
    at org.omnifaces.persistence.service.BaseEntityService.getPage(BaseEntityService.java:1485)

Maybe use a prefix specific to OmniPersistence?

BalusC commented 6 years ago

It's more likely that manually setting a cache region is unnecessary. Perhaps I'd better just remove the entire org.hibernate.cacheRegion hint. I'll have to test that first.