0 Replies Latest reply on Apr 13, 2010 4:19 PM by Shri Shrimad

    Classloader issue when persistence unit and ejb in different jars - how to solve?

    Shri Shrimad Newbie

      Hello,

       

      For example, I have two jars:

       

      1. JpaLib.jar, which contain entity class (for example, Account) and persistence unit JpaLibPU.

      2. JpaBean.jar, which contain ejb3 SLSB, which uses JpaLibPU to get Account from database.

       

       

      @Stateless
      public class JpaTestBean implements ...
      {
          @PersistenceContext(unitName="JpaLibPU")
          private EntityManager em;

          public Account getAccount( String id )
          {
               return em.find( Account.class, id );
          }
      }

       

      After deploy, all works ok.

       

      When I redeploy JpaLib.jar (add another entity class, for example), JpaBean.jar is stopped and started again, when JpaLibPU becomes available.

       

      But, when I invoke getAccount I get exception: "java.lang.ClassCastException: tst.entity.Account cannot be cast to tst.entity.Account". As I understand, this happens due Account in JpaBean.jar and Account in JpaLib.jar loaded using defferent classloaders.

       

      If I manually "touch" JpaBean.jar - jboss redeploy it and all works fine again.

       

      How can I force JBoss to automatically redeploy (not just stop/start) JpaBean.jar when JpaLib.jar is redeployed?

       

      Any ideas?

       

      PS: JBoss version 5.1 or 6 M2