org.hibernate.WrongClassException when loading entity from a shared cache region in JBoss EAP 7

Solution Verified - Updated -

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 of over 48,000 articles and solutions.

Current Customers and Partners

Log in for full access

Log In
Close

Welcome! Check out the Getting Started with Red Hat page for quick tours and guides for common tasks.