4 Replies Latest reply on Jul 23, 2011 2:04 PM by John Franey

    jboss as 6: perplexed by classloading

    John Franey Novice

      In short: what is best deployment model for my project? and what information is needed in configuration files to make this best deployment model work?

       

      I have two applications that are dependent on the same model.  One app is a seam gui.  One app is an EJB that is a client to a web service.  The model is implemented as JPA entities and there are a few common business rules implemented as session beans.

       

      My first approach is to put the JPA entities and business rules in an ejb archive (model.ejb) and bundle that in each of the two apps. (gui.ear, and webclient.ear).  The downside is

      • we cannot easily see what release of the model.ejb our apps are using.
      • there would be two binaries of model.ejb in deploy directory, one deployed with each app, and versions have to be the same, requiring a repackaging of an app even if it is not affected by a new version of the model.
      • the persistence.xml file is in the entities jar, and jboss tries to load both; one fails because they both have the same persistence unit name.

       

      So, second approach was to build an ear with entities and the few common session beans.  I could not get this exactly right in terms of configuration.  In this ear, I provided the jboss-classloading.xml file, with these contents:

       

      <classloading xmlns="urn:jboss:classloading:1.0"

          parent-domain="DefaultDomain"

          export-all="NON_EMPTY"

          import-all="true">

      </classloading>

       

      The intent is to export the jpa classes to the apps through a common classloader.  This seemed to work but only on the first jboss installed system that I was using to develop.  When I moved it to an integration system, it stopped working, or I fat fingered a configuration along the way.   A named query defined on the jpa entity in the model ear is not found in a call to createNamedQuery by at least one of the other apps (the web client app).   Why would this named query resolve in one system and not another (what did I screw up in the transition)?  <scratch, scratch>

       

       

      So, now, down to a third approach, and just for grins:  I deploy the model and the common session beans as separate normal jar files.  jboss-classloading.xml file is absent in both.  This seems to work, and I don't know why.

       

       

      So, I prefer the second deployment, but I don't know why it doesn't work.  I'd use the third if I have to, but I don't know why it does work.  Is there a jee specification or jboss document that would clarify?  or are the answers earned only be trial of fire?   In any case, any advice from an expert?

       

      Thanks.

        • 1. Re: jboss as 6: perplexed by classloading
          Ales Justin Master

          So, now, down to a third approach, and just for grins:  I deploy the model and the common session beans as separate normal jar files.  jboss-classloading.xml file is absent in both.  This seems to work, and I don't know why.

          JBossAS6 by default uses shared CL domains aka "big-ball-o-mud".

          And since there is no jboss-classloading.xml / explicit CL info, both your apps share the same CL domain == see each other.

           

          .ear files are isolated by default since (including) AS6, where they weren't before.

          • 2. Re: jboss as 6: perplexed by classloading
            John Franey Novice

            Thanks.

             

            Although, I'm still stuck.

             

            With a model ear (containing a persistence.xml) exposing its classes to the world with jboss-classloading.xml, another ear file can apparently see the classes.  However, this other ear file cannot see the persistence.xml file and so when it tries to run a named query (annotated on the class), it fails.  Can't I setup the app to see and share the persistence unit created by the model ear deploy?

            • 3. Re: jboss as 6: perplexed by classloading
              Ales Justin Master

              Can't I setup the app to see and share the persistence unit created by the model ear deploy?

              Hmm, dunno.

              I know one can see EJBs, if shared, but I doubt this works for PUs as well.

               

              I suggest you expose those queries via EJBs / DAOs.

              • 4. Re: jboss as 6: perplexed by classloading
                John Franey Novice

                Finally, I got this.  The reason for not finding the named queries in the case where a set of jar files are deployed separately instead of together in an ear file is........

                 

                 

                .....the @PersistenceContext MUST have a unitName specified.

                 

                 

                If in an ear, I had two modules, an bean module and an entity (jpa) module. Instead of deploy as an ear I deploy the two modules as regular ol' jar files. (ROJF?), injecting a persistence context into a bean without a unit name simply does not work.  If in an ear file, a rule can be followed by the deployer, and would be to inject the persistence context of any name from the same ear file.  As ROJF, this rule cannot be followed.

                 

                Thanks.