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.
+Possible solution?+ _I believe that SessionFactoryImpl#determineCollectionRegionAccessStrategy should pull and cast from cacheAccessStrategiesMap as RegionAccessStrategy. Then check if the accessStrategy is an instanceof CollectionRegionAccessStrategy._
{code:java} // shares a region with the collection cache @Cache(region="com.test.EntityA") public class EntityA { }
public class EntityB { // Shares a region @Cache(region="com.test.EntityA") public List<EntityA> getEntities() { return entities; } } {code}
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}} |
|