We're updating the issue view to help you get more done. 

ClassCastException thrown in SessionFactoryImpl for named regions containing both entity and collection

Description

Test case:

  • using Hibernate 5.0.6 with ehcache;

1 2 3 4 5 6 <?xml version="1.0" encoding="UTF-8"?> <ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://www.ehcache.org/ehcache.xsd" updateCheck="false" monitoring="autodetect" dynamicConfig="true"> <cache name="configurationCache" eternal="false" timeToLiveSeconds="3600" maxEntriesLocalHeap="500"/> </ehcache>
  • annotating the entity classes with @Cache

    1 2 3 4 5 6 7 8 @Entity @Cache(usage = org.hibernate.annotations.CacheConcurrencyStrategy.READ_WRITE, region = "someConfigurationCache") public class SomeConfiguration implements Serializable { @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true) @JoinColumn(name = "some_configuration_id", referencedColumnName = "id") @Cache(usage = org.hibernate.annotations.CacheConcurrencyStrategy.READ_WRITE, region = "otherConfigurationCache") private List<OtherConfiguration> confList; }
  • both "someConfigurationCache" and "otherConfigurationCache" are reused for entity and collection as well.
    The result is "org.hibernate.cache.ehcache.internal.nonstop.NonstopAwareEntityRegionAccessStrategy cannot be cast to org.hibernate.cache.spi.access.CollectionRegionAccessStrategy", because the method determineCollectionRegionAccessStrategy in SessionFactoryImpl finds a region with the name required, but it is an entity region, not a collection region.
    The same scenario works with 5.0.3.

Environment

None

Status

Assignee

Galder Zamarreno

Reporter

Gabriel Deroude

Labels

Worked in

None

Feedback Requested

None

Feedback Requested By

None

backPortable

None

Community Help Wanted

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

backportReEvaluate

None

Components

Fix versions

Affects versions

5.0.6
5.1.10

Priority

Major