4 Replies Latest reply: Jun 5, 2009 12:17 AM by 807588 RSS

    Classpath problem when deploying a persistence unit (in JBoss)

    807588
      Hello,
      I have a JAR file containing an EJB with a persistence.xml file.
      I also have another JAR project containing a persistent annotated POJO class that the persistence unit is supposed to map.

      I defined the class in the persistence unit using a class XML element, but because it's in another JAR, the persistence unit implementation cannot find it. I tried to use a jar-file element instead and specify the name of the JAR containing the POJO, and from the log it seems the class is found and identified as persistent, but then the actual mapping operation fails because of the same reason! I also tried to edit the classpath property in the EJB JAR's manifest fileto include the POJO JAR, but that did not help too...

      Does anyone know what I'm missing here and how to make the persistence unit succeed in mapping the POJO class?
      Thanks.
        • 1. Re: Classpath problem when deploying a persistence unit (in JBoss)
          807588
          Can anybody help me, please?
          Thanks.
          • 2. Re: Classpath problem when deploying a persistence unit (in JBoss)
            807588
            Ok, some more details regarding the problem:
            Here is the persistence unit definition:
            <persistence-unit name="NorthwindPU" transaction-type="JTA">
                      <provider>org.hibernate.ejb.HibernatePersistence</provider>
                      <jta-data-source>jdbc/NorthwindDB</jta-data-source>
                      <!-- <class>personal.test.domain_layer.Product</class> -->
                      <jar-file>TestProjectPersistence.jar</jar-file>
                      <properties>
                           <property name="hibernate.transaction.factory_class" 
                                value="org.hibernate.transaction.CMTTransactionFactory"/>
                           <property name="hibernate.transaction.manager_lookup_class" 
                                value="org.hibernate.transaction.JBossTransactionManagerLookup"/>
                           <property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect"/>
                           <property name="hibernate.current_session_context_class" value="jta"/>
                      </properties>
            </persistence-unit>
            Here is the stack trace I get when starting the server and deploying the application:
            javax.persistence.PersistenceException: [PersistenceUnit: NorthwindPU] class or package not found
                 at org.hibernate.ejb.Ejb3Configuration.addNamedAnnotatedClasses(Ejb3Configuration.java:1093)
                 at org.hibernate.ejb.Ejb3Configuration.addClassesToSessionFactory(Ejb3Configuration.java:871)
                 at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:758)
                 at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:425)
                 at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:131)
                 at org.jboss.jpa.deployment.PersistenceUnitDeployment.start(PersistenceUnitDeployment.java:301)
                 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                 at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
                 at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
                 at java.lang.reflect.Method.invoke(Unknown Source)
                 at org.jboss.reflect.plugins.introspection.ReflectionUtils.invoke(ReflectionUtils.java:59)
                 at org.jboss.reflect.plugins.introspection.ReflectMethodInfoImpl.invoke(ReflectMethodInfoImpl.java:150)
                 at org.jboss.joinpoint.plugins.BasicMethodJoinPoint.dispatch(BasicMethodJoinPoint.java:66)
                 at org.jboss.kernel.plugins.dependency.KernelControllerContextAction$JoinpointDispatchWrapper.execute(KernelControllerContextAction.java:241)
                 at org.jboss.kernel.plugins.dependency.ExecutionWrapper.execute(ExecutionWrapper.java:47)
                 at org.jboss.kernel.plugins.dependency.KernelControllerContextAction.dispatchExecutionWrapper(KernelControllerContextAction.java:109)
                 at org.jboss.kernel.plugins.dependency.KernelControllerContextAction.dispatchJoinPoint(KernelControllerContextAction.java:70)
                 at org.jboss.kernel.plugins.dependency.LifecycleAction.installActionInternal(LifecycleAction.java:221)
                 at org.jboss.kernel.plugins.dependency.InstallsAwareAction.installAction(InstallsAwareAction.java:54)
                 at org.jboss.kernel.plugins.dependency.InstallsAwareAction.installAction(InstallsAwareAction.java:42)
                 at org.jboss.dependency.plugins.action.SimpleControllerContextAction.simpleInstallAction(SimpleControllerContextAction.java:62)
                 at org.jboss.dependency.plugins.action.AccessControllerContextAction.install(AccessControllerContextAction.java:71)
                 at org.jboss.dependency.plugins.AbstractControllerContextActions.install(AbstractControllerContextActions.java:51)
                 at org.jboss.dependency.plugins.AbstractControllerContext.install(AbstractControllerContext.java:348)
                 at org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:1598)
                 at org.jboss.dependency.plugins.AbstractController.incrementState(AbstractController.java:934)
                 at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:1062)
                 at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:984)
                 at org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:774)
                 at org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:540)
                 at org.jboss.deployers.vfs.deployer.kernel.BeanMetaDataDeployer.deploy(BeanMetaDataDeployer.java:121)
                 at org.jboss.deployers.vfs.deployer.kernel.BeanMetaDataDeployer.deploy(BeanMetaDataDeployer.java:51)
                 at org.jboss.deployers.spi.deployer.helpers.AbstractSimpleRealDeployer.internalDeploy(AbstractSimpleRealDeployer.java:62)
                 at org.jboss.deployers.spi.deployer.helpers.AbstractRealDeployer.deploy(AbstractRealDeployer.java:50)
                 at org.jboss.deployers.plugins.deployers.DeployerWrapper.deploy(DeployerWrapper.java:171)
                 at org.jboss.deployers.plugins.deployers.DeployersImpl.doDeploy(DeployersImpl.java:1439)
                 at org.jboss.deployers.plugins.deployers.DeployersImpl.doInstallParentFirst(DeployersImpl.java:1157)
                 at org.jboss.deployers.plugins.deployers.DeployersImpl.doInstallParentFirst(DeployersImpl.java:1178)
                 at org.jboss.deployers.plugins.deployers.DeployersImpl.doInstallParentFirst(DeployersImpl.java:1210)
                 at org.jboss.deployers.plugins.deployers.DeployersImpl.install(DeployersImpl.java:1098)
                 at org.jboss.dependency.plugins.AbstractControllerContext.install(AbstractControllerContext.java:348)
                 at org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:1598)
                 at org.jboss.dependency.plugins.AbstractController.incrementState(AbstractController.java:934)
                 at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:1062)
                 at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:984)
                 at org.jboss.dependency.plugins.AbstractController.change(AbstractController.java:822)
                 at org.jboss.dependency.plugins.AbstractController.change(AbstractController.java:553)
                 at org.jboss.deployers.plugins.deployers.DeployersImpl.process(DeployersImpl.java:781)
                 at org.jboss.deployers.plugins.main.MainDeployerImpl.process(MainDeployerImpl.java:698)
                 at org.jboss.system.server.profileservice.ProfileServiceBootstrap.loadProfile(ProfileServiceBootstrap.java:304)
                 at org.jboss.system.server.profileservice.ProfileServiceBootstrap.start(ProfileServiceBootstrap.java:205)
                 at org.jboss.bootstrap.AbstractServerImpl.start(AbstractServerImpl.java:405)
                 at org.jboss.Main.boot(Main.java:209)
                 at org.jboss.Main$1.run(Main.java:547)
                 at java.lang.Thread.run(Unknown Source)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        
            • 3. Re: Classpath problem when deploying a persistence unit (in JBoss)
              807588
              Here is the rest of the stack trace (had to split it because the message was too long):
              Caused by: java.lang.ClassNotFoundException: personal.test.domain_layer.Product from BaseClassLoader@192563a  { had to cut the rest of the line because it caused the message to exceed the maximum length allowed }
                   at org.jboss.classloader.spi.base.BaseClassLoader.loadClass(BaseClassLoader.java:422)
                   at java.lang.ClassLoader.loadClass(Unknown Source)
                   at java.lang.ClassLoader.loadClassInternal(Unknown Source)
                   at java.lang.Class.forName0(Native Method)
                   at java.lang.Class.forName(Unknown Source)
                   at org.hibernate.util.ReflectHelper.classForName(ReflectHelper.java:135)
                   at org.hibernate.ejb.Ejb3Configuration.classForName(Ejb3Configuration.java:1009)
                   at org.hibernate.ejb.Ejb3Configuration.addNamedAnnotatedClasses(Ejb3Configuration.java:1081)
                   ... 54 more
              So it seems Hibernate Entity Manager manages to find the annotated Product class that is in the TestProjectPersistence.jar, but then it has to use the class loader to load the class file, and the loader fails in finding it.

              What can I do in order to make the class loader find the JAR file? As I stated in the first message, it's not the same JAR file as the one that the persistence.xml is found in, but they are both deployed in the same EAR file.
              Thanks.
              • 4. Re: Classpath problem when deploying a persistence unit (in JBoss)
                807588
                Trying again to get an answer...