I've been trying to fix an issue for some time now.
I have two EAR files being deployed to Wildfly 8.1.0 with the same EJB.jar and the same JPA.jar, but with seperate EJB.jars for 'Scheduling' A.K.A running the different functions within the EJBs. The schedulers access the EJB.jars which in turn access the JPA.jars. Both EARs/JPAs use the same database.
The layout of the two EARs are as follows:
EAR1:
SCHEDULER1-EJB.jar
EJB.jar
lib\JPA.jar
EAR2:
SCHEDULER2-EJB.jar
EJB.jar
lib\JPA.jar
Everything deploys fine, but after a few minutes of the schedulers running I get a ClassCastException for user defined classes. Example:
java.lang.ClassException: persistence.Foo cannot be cast to persistence.Foo
I have tried playing around with Dependency, Class-Path and EAR isolation techniques but cannot fix my issue.
The issue only occurs when both EARs are deployed and running, individually they run without any issues.
Any suggestions would be welcome. Thanks in advance.
I don't know how Jboss handles persistence-Units with same name internally, but it seems there is some process of sharing between those. One of your JPA.jars already holds an object in the cache, and later the other JPA.jar tries to reuse it.
Application-servers create their own classloader for each ear/war. You try to pass an object from war1 to war2 and war2 tries to cast the object, but can't.
Solution: Create an EAR containg your JPA and EJB.jar and deploy both schedular-jars.
your deployment-folder would look like this:
.) Backend.ear
.) Schedular1.jar
.) Schedular2.jar