ClassCastException when using L2Cache with "structured_cache"=true

Description

The problem was introduced with the HHH-11097, see some backround at: ClassCastException: Object; cannot be cast to Collection.

Have a local tetscase written for the problem in org.hibernate.test.querycache.QueryCacheTest and will push that.

The root caus is the method that creates the "loggableString" that was changed in the above HHH-11097. However there are a few precondition that is needed to see the problem:

  • USE_SECOND_LEVEL_CACHE = true

  • USE_STRUCTURED_CACHE = true

Then the class that is to be persisted into the L2Cache must have an embededId and at least some attribute that is a "OneToMany", "MenuToMany", etc. The fault occurs when we get a hit in the L2Cache when we try to read it:

{{Caused by: java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to java.util.Collection
at org.hibernate.type.CollectionType.getElementsIterator(CollectionType.java:250)
at org.hibernate.type.CollectionType.renderLoggableString(CollectionType.java:208)
at org.hibernate.type.CollectionType.toLoggableString(CollectionType.java:198)
at org.hibernate.type.TypeHelper.toLoggableString(TypeHelper.java:439)
at org.hibernate.cache.spi.entry.StructuredCacheEntry.destructure(StructuredCacheEntry.java:54)
at org.hibernate.event.internal.DefaultLoadEventListener.processCachedEntry(DefaultLoadEventListener.java:612)
at org.hibernate.event.internal.DefaultLoadEventListener.loadFromSecondLevelCache(DefaultLoadEventListener.java:602)
at org.hibernate.event.internal.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:462)
at org.hibernate.event.internal.DefaultLoadEventListener.load(DefaultLoadEventListener.java:219)
at org.hibernate.event.internal.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:278)
at org.hibernate.event.internal.DefaultLoadEventListener.doOnLoad(DefaultLoadEventListener.java:121)
at org.hibernate.event.internal.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:89)
at org.hibernate.internal.SessionImpl.fireLoad(SessionImpl.java:1239)
at org.hibernate.internal.SessionImpl.internalLoad(SessionImpl.java:1122)
at org.hibernate.type.EntityType.resolveIdentifier(EntityType.java:646)
at org.hibernate.type.EntityType.resolve(EntityType.java:431)
at org.hibernate.engine.internal.TwoPhaseLoad.doInitializeEntity(TwoPhaseLoad.java:165)
at org.hibernate.engine.internal.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:125)
at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:1152)
at org.hibernate.loader.Loader.processResultSet(Loader.java:1011)
at org.hibernate.loader.Loader.doQuery(Loader.java:949)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:341)
at org.hibernate.loader.Loader.doList(Loader.java:2692)
at org.hibernate.loader.Loader.doList(Loader.java:2675)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2507)
at org.hibernate.loader.Loader.list(Loader.java:2502)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:502)
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:384)
at org.hibernate.engine.query.spi.HQLQueryPlan.performList(HQLQueryPlan.java:216)
at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1490)
at org.hibernate.query.internal.AbstractProducedQuery.doList(AbstractProducedQuery.java:1445)
at org.hibernate.query.internal.AbstractProducedQuery.list(AbstractProducedQuery.java:1414)
at org.hibernate.query.Query.getResultList(Query.java:146)
at org.hibernate.query.criteria.internal.compile.CriteriaQueryTypeQueryAdapter.getResultList(CriteriaQueryTypeQueryAdapter.java:72)}}

Environment

None

Status

Assignee

Unassigned

Reporter

Jörgen Risholt

Fix versions

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

backportDecision

None

Worked in

5.2.2

Components

Affects versions

Priority

Major
Configure