1 Reply Latest reply: Aug 9, 2012 9:00 AM by JamesSutherland RSS

    Weblogic classloader issue

    436348
      Hi,

      I'm trying to resolve a "cannot be cast" error on Oracle JDeveloper 11.1.2.2.0. My application is using eclipselink JPA provider, which works fine on a fresh start WLS. However, when I redeployed my application without restarting the WLS, I got a very strange runtime error:

      gov.noaa.gcld.model.jpa.User cannot be cast to gov.noaa.gcld.model.jpa.User

      The code is:

      List<User> users = dao.findByUserLdapId(userId);

      The compile has no error. I checked the classloader of the User object returned by the entityManager. This is what I've found:

      1) When I did a fresh start of the WLS,

      The classloader of User object in my application: weblogic.utils.classloaders.ChangeAwareClassLoader@1bf353c
      The classloader of User object returned from the entity manager: weblogic.utils.classloaders.ChangeAwareClassLoader@1bf353c

      The application is working fine at this time.

      2) When I redeployed my application without restarting the WLS,

      The classloader of User object in my application: weblogic.utils.classloaders.ChangeAwareClassLoader@14e4ae9
      The classloader of User object returned from the entity manager: weblogic.utils.classloaders.ChangeAwareClassLoader@1bf353c

      Now I got the "gov.noaa.gcld.model.jpa.User cannot be cast to gov.noaa.gcld.model.jpa.User" error.

      It looks the WLS is using a new classloader when I redeploy my application but still using the old classoloader for eclipselink entity manager, even after I undeployed my application completely, and there's no other applications using the same persistence unit.

      Does anybody know how to force the WLS to reload the eclipselink entity manager using the same classloader as the application? Our server admin will not restart the WLS when we redeploy our applications.

      Thanks very much for your help!
        • 1. Re: Weblogic classloader issue
          JamesSutherland
          I assume you are using a non (application) managed persistence unit. For application managed persistence units you are responsible for closing the EntityManagerFactory when undeploying.
          If any EntityManagerFactory are not closed, then the old persistence unit remains deployed, and will have the wrong class loader.

          See,
          https://bugs.eclipse.org/bugs/show_bug.cgi?id=326552