ClassCastException: Using a region shared by entity caching on a collection cache

Description

If a region is specified as both an Entity region (class level) and a Collection region (on a @OneToMany association) then it will result in a ClassCastException on startup.

I originally used the same region name because I believed that they would pull from the same cache.

Caused by: java.lang.ClassCastException: org.hibernate.cache.ehcache.internal.nonstop.NonstopAwareEntityRegionAccessStrategy cannot be cast to org.hibernate.cache.spi.access.CollectionRegionAccessStrategy
at org.hibernate.internal.SessionFactoryImpl.determineCollectionRegionAccessStrategy(SessionFactoryImpl.java:624)
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:389)
at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:465)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:708)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:724)
at org.springframework.orm.hibernate4.LocalSessionFactoryBuilder.buildSessionFactory(LocalSessionFactoryBuilder.java:372)
at org.springframework.orm.hibernate4.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:454)
at org.springframework.orm.hibernate4.LocalSessionFactoryBean.afterPropertiesSet(LocalSessionFactoryBean.java:439)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1637)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1574)
... 59 more}}

Environment

Java 7, Spring 4.3.2

Activity

Show:
John Strickler
August 11, 2016, 8:05 PM

Possible solution?
I believe that SessionFactoryImpl#determineCollectionRegionAccessStrategy should pull and cast from cacheAccessStrategiesMap as RegionAccessStrategy. Then check if the accessStrategy is an instanceof CollectionRegionAccessStrategy.

Assignee

Unassigned

Reporter

John Strickler

Fix versions

None

Labels

backPortable

None

Suitable for new contributors

Yes, likely

Requires Release Note

None

Pull Request

None

backportDecision

None

Affects versions

Priority

Minor
Configure