Using Spring+JPA+Hibernate+Ehcache.
I am trying to cache Hibernate Collections in L2 Cache(Using EhCache).
The entity is annotated with @Cache(region=abc,strategy=READ_WRITE)
When I try to annotate the LAZY/EAGER loaded collection with @Cache annotation with same configurations, it results into the below mentioned exception:
java.lang.ClassCastException: org.hibernate.cache.ehcache.internal.nonstop.NonstopAwareEntityRegionAccessStrategy cannot be cast to org.hibernate.cache.spi.access.CollectionRegionAccessStrategy
The agenda here is to cache, all the data in the database on application start, to get the best performance.
The work-around to this apparent bug is to name your collection and entity regions differently:
@Entity
@Cache(usage=CacheConcurrencyStrategy.READ_ONLY, region="foo")
public class Foo {
@Cache(usage=CacheConcurrencyStrategy.READ_WRITE, region="bar-list")
@OneToMany
private List<Bar> bars = new ArrayList<>();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With