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

Solution Verified - Updated -

Issue

  • 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="http://java.sun.com/xml/ns/persistence"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
   version="1.0">

  <persistence-unit name="example-jpa.jar" transaction-type="RESOURCE_LOCAL">
    ...
    <properties>
         ...
         <property name="jboss.entity.manager.factory.jndi.name" value="java:/ExampleEntityManagerFactory"/>

    </properties>
  </persistence-unit>
</persistence>

Environment

  • 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