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, tools, and much more.

Current Customers and Partners

Log in for full access

Log In

New to Red Hat?

Learn more about Red Hat subscriptions

Using a Red Hat product through a public cloud?

How to access this content