org.hibernate.WrongClassException when loading entity from a shared cache region in JBoss EAP 7
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,
WrongClassException
is 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) ...
Environment
- Red Hat JBoss Enterprise Application Platform (EAP) 7
- Hibernate 5
- Infinispan 8
Subscriber exclusive content
A Red Hat subscription provides unlimited access to our knowledgebase, tools, and much more.