org.hibernate.WrongClassException when loading entity from a shared cache region in JBoss EAP 7
Environment
- Red Hat JBoss Enterprise Application Platform (EAP) 7
- Hibernate 5
- Infinispan 8
Issue
-
Two root entities share the same cache region and may have equivalent key values
@Entity @Cache(... region="shared-region") public class Employee ... { @Id private String name; ... } @Entity @Cache(... region="shared-region") public class Candidate ... { @Id private String name; ... } -
When retrieving an entity (e.g. by ID) from the cache,
WrongClassExceptionis sometimes raised.... org.hibernate.WrongClassException: Object [id=John Smith] was not of the specified subclass [support.hibernate.entity.Employee] : loaded object was of wrong class class support.hibernate.entity.Candidate ... at org.hibernate.jpa.spi.AbstractEntityManagerImpl.find(AbstractEntityManagerImpl.java:1075) ...
Resolution
Content from issues.jboss.org is not included.JBEAP-7483 is resolved in Red Hat JBoss Enterprise Application Platform (EAP) 7.0 CP05 and later.
Root Cause
- This is a known defect (Content from issues.jboss.org is not included.JBEAP-7483)
- See also Content from hibernate.atlassian.net is not included.HHH-11083
Components
Category
This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.