5 Replies Latest reply on Oct 20, 2006 3:57 AM by Niclas Lindberg

    Sharing EJB3 classes in a .jar creates "Unknown entity:" Exc

    Niclas Lindberg Newbie

      Hello all!

      Packaging problem... We have different subsystems each one packaged in a .jar file and all of the subsystems packaged together in an .ear.

      Well.. The public part (classes used by other subsystems) of each subsystem is excluded from the subsystem.jar and packed together into a subsystems-shared.jar. Subsystems-shared.jar is referenced to from subsystemA.jar .. subsystemX.jar with manifest Class-Path attribute.

      The problem is that when I move any EJB3 entity beans out into the subsystems-shared.jar the subsystem using that entitybean finds the class (Class loading is ok). But the EntityManager throws an Exception saying "Unknown Entity: ". When I move the EJB3 entity beans back into the subsystem.jar it works.

      Is there anything I'm missing?

      Any best practices. This is how you do it - guide! available or am I missing something trivial?

      Thanks for any reply!

      Take care,
      Niclas

        • 1. Re: Sharing EJB3 classes in a .jar creates
          Andrew Rubinger Master

          When you moved your entity beans into "subsystems-shared.jar", are you also moving the persistence.xml? And removing persistence.xml from "subsystem.jar"?

          Boot up and take a look at the JMX Console, under the heading "persistence.units". If you see more than one entry, and an EAR>JAR>UNITNAME one, this could be a clue that you're services are trying to use the wrong persistence unit (I accidentally did this recently).

          Good luck.

          S,
          ALR

          • 2. Re: Sharing EJB3 classes in a .jar creates
            Niclas Lindberg Newbie

            Hi Al!

            Thanks for your reply. Unfortunally the error remains..

            From the JMX console.
            persistence.units
            ear=system.ear,jar=accountsystem.jar,unitName=AccountSystem

            accountsystem.jar references shared-susbsystems.jar with a Class-Path attribute in the manifest. The Entity EJB3 classes are in the shared-subsystems.jar and the persistence.xml is the accountsystem.jar's meta-inf directory.

            The classes loads. In my bean I do this on the first line in the method:
            log.info("This: " + this.getClass().getClassLoader());
            log.info("User: " + user.getClass().getClassLoader());

            And the result is:
            [AccountSystem] This: org.jboss.mx.loading.UnifiedClassLoader
            3@19a639b{ url=file:/C:/Program/jboss-4.0.4.GA/server/default/tmp/deploy/tmp5726
            0system.ear ,addedOrder=51}
            [AccountSystem] User: org.jboss.mx.loading.UnifiedClassLoader
            3@19a639b{ url=file:/C:/Program/jboss-4.0.4.GA/server/default/tmp/deploy/tmp5726
            0system.ear ,addedOrder=51}

            Same classloader... I don't understand..

            Thanks anyone for anyhelp!!

            • 3. Re: Sharing EJB3 classes in a .jar creates
              Andrew Rubinger Master

               

              "niclas.lindberg" wrote:
              The Entity EJB3 classes are in the shared-subsystems.jar and the persistence.xml is the accountsystem.jar's meta-inf directory.


              Yep - the error isn't due to classloading; it's to the container not recognizing your classes as entities.

              Throw persistence.xml into META-INF of shared-subsystems.jar, where your entities are, and give that a whirl.

              S,
              ALR


              • 4. Re: Sharing EJB3 classes in a .jar creates
                Niclas Lindberg Newbie

                Hi Al! Thanks again... unfortunally same error.

                I moved persistence.xml into subsystem-shared.jar and registered it in application.xml as and removed persisitence.xml from accountsystem.jar.

                Same Exception "Unknown Entity".

                It simply doesn't seem to work if the EJB3 entities AND the persistence.xml AND the EntityManager(UnitName=xxx) is not defined in the same .jar.

                Can it really be like that??

                I think it would be great if you could reuse the same entities and persist them through different PersistenceContexts anywhere in the system...

                My wish is simple...

                I want each subsystem to be as independent as possible. In case of dependency I want to put all dependent classes in a shared.jar for each subsystem.jar to reference to to not get any classloading problems. (Classic approach)

                Basiucally the dependent classes are: SessionBean interfaces, Exceptions and DataObjects. The dataobjects are Ejb3 entities.

                How do I package it to work?

                My idea is that each subsystem put different aspects on the data.... So if I create one dataaccess subsystem and have all entity access go through there and define the whole domainmodel in that .jar I't becomes a mess when the system evolves...

                I would like each subsystem to handle its own datamodel with some systemwide dataclassess(Basically PKs with some systemwide attributes) available..

                Thanks thanks thanks for your involvement so far!!

                • 5. Re: Sharing EJB3 classes in a .jar creates
                  Niclas Lindberg Newbie

                  Problem solved!!

                  In persistence.xml add:

                  <jar-file>../subsystem-shared.jar</jar-file>

                  Makes the deployer scan for files in the shared jar..

                  Why the ../ is used I don't know.. Doesn't find it otherwise..

                  Thanks anyhow for the help! Hope this helps someone else..