ClassCastException casting to same class when EntityManager is shared between two isolated applications in JBoss EAP?

Solution Verified - Updated -


  • We have two applications running on EAP. Both applications are packaged as EARs. We are getting this exception:
Caused by: java.lang.ClassCastException: com.jboss.examples.jpa.ExampleEntity cannot be cast to com.jboss.examples.jpa.ExampleEntity

We think this is a Class Loader isolation problem. The class com.jboss.examples.jpa.ExampleEntity is contained in a common JAR along with a persistence.xml that is packaged in both EARs. We have isolation enable on both EARs. The common JAR has a persistence.xml which is specifying the JNDI name for the EntityManagerFactory as such:

<persistence xmlns=""

  <persistence-unit name="example-jpa.jar" transaction-type="RESOURCE_LOCAL">
         <property name="" value="java:/ExampleEntityManagerFactory"/>



  • JBoss Enterprise Application Platform (EAP)
    • 5.x

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