5 Replies Latest reply on Oct 11, 2011 10:15 AM by Scott Marlow

    JPA 1.0 provider (OpenJPA 1.2.2) on jboss-as-7.1.0.Alpha2-SNAPSHOT result in ClassCastException

    vmariusvv Newbie

      Hi,

       

      I'm trying to run a application that has JPA 1.0, EJB 3.0 on jboss-as-7.1.0.Alpha2-SNAPSHOT.

       

      I've build a module for OpenJPA 1.2.2 with dependencies on geromino specs:

       

      org.apache.openjpa module:

      <module xmlns="urn:jboss:module:1.0" name="org.apache.openjpa">

        <resources>

          <resource-root path="openjpa-1.2.2.jar"/>

        </resources>

       

         <dependencies>

           <module name="javax.api"/>

           <module name="org.apache.geronimo.specs.geronimo-jpa_1_0_spec"/>

           <module name="org.apache.geronimo.specs.geronimo-jta_1_1_spec"/>

           <module name="org.apache.commons.collections" slot="3.2"/>

           <module name="org.apache.commons.lang" slot="2.1"/>

           <module name="org.apache.commons.pool" />

           <module name="net.sourceforge.serp" />

         </dependencies>

      </module>

       

      org.apache.geronimo.specs.geronimo-jpa_1_0_spec module:

      <module xmlns="urn:jboss:module:1.0" name="org.apache.geronimo.specs.geronimo-jpa_1_0_spec">

          <dependencies>

              <!-- This dep is for javax.naming -->

              <module name="javax.api" export="true"/>

          </dependencies>

       

          <resources>

              <resource-root path="geronimo-jpa_1.0_spec-1.1.2.jar"/>

              <!-- Insert resources here -->

          </resources>

      </module>

       

      org.apache.geronimo.specs.geronimo-jta_1_1_spec module:

      <module xmlns="urn:jboss:module:1.0" name="org.apache.geronimo.specs.geronimo-jta_1_1_spec">

          <dependencies>

              <!-- This dep is for javax.naming -->

              <module name="javax.api" export="true"/>

          </dependencies>

       

           <resources>

              <resource-root path="geronimo-jta_1.1_spec-1.1.1.jar"/>

              <!-- Insert resources here -->

          </resources>

      </module>

       

      org.apache.geronimo.specs.geronimo-ejb_3_0_spec" module:

      <module xmlns="urn:jboss:module:1.0" name="org.apache.geronimo.specs.geronimo-ejb_3_0_spec">

          <dependencies>

              <!-- This dep is for javax.naming -->

              <module name="javax.api" export="true"/>

              <module name="org.apache.geronimo.specs.geronimo-annotation_1_0_spec" export="true"/>

              <module name="org.apache.geronimo.specs.geronimo-interceptor_3_0_spec" export="true"/>

              <module name="org.apache.geronimo.specs.geronimo-jta_1_1_spec" export="true"/>

          </dependencies>

       

          <resources>

              <resource-root path="geronimo-ejb_3.0_spec-1.0.1.jar"/>

              <!-- Insert resources here -->

          </resources>

      </module>

       

       

      org.apache.geronimo.specs.geronimo-annotation_1_0_spec module:

      <module xmlns="urn:jboss:module:1.0" name="org.apache.geronimo.specs.geronimo-annotation_1_0_spec">

          <dependencies>

              <!-- This dep is for javax.naming -->

              <module name="javax.api" export="true"/>

          </dependencies>

       

           <resources>

              <resource-root path="geronimo-annotation_1.0_spec-1.1.1.jar"/>

              <!-- Insert resources here -->

          </resources>

      </module>

       

       

      org.apache.geronimo.specs.geronimo-interceptor_3_0_spec module:

      <module xmlns="urn:jboss:module:1.0" name="org.apache.geronimo.specs.geronimo-interceptor_3_0_spec">

          <dependencies>

              <!-- This dep is for javax.naming -->

              <module name="javax.api" export="true"/>

          </dependencies>

       

           <resources>

              <resource-root path="geronimo-interceptor_3.0_spec-1.0.1.jar"/>

              <!-- Insert resources here -->

          </resources>

      </module>

       

      net.sourceforge.serp module:

      <module xmlns="urn:jboss:module:1.0" name="net.sourceforge.serp">

          <resources>

              <resource-root path="serp-1.13.1.jar"/>

              <!-- Insert resources here -->

          </resources>

       

           <dependencies>

               <module name="org.junit" slot="3.8.1"/>

          </dependencies>

      </module>

       

       

      After this I modified the following files:

       

      standalone.xml:

              <subsystem xmlns="urn:jboss:domain:ee:1.0">

                  <ear-subdeployments-isolated>

                      false

                  </ear-subdeployments-isolated>

                  <global-modules>

                      <module name="org.apache.openjpa" slot="main"/>

                  </global-modules>

              </subsystem>

       

      jboss-deployement-structure.xml:

      <?xml version="1.0" encoding="UTF-8"?>

      <jboss-deployment-structure>

                <ear-subdeployments-isolated>false</ear-subdeployments-isolated>

                <deployment>

                          <exclusions>

                                    <module name="javax.annotation.api" />

                                    <module name="javax.ejb.api" />

                                    <module name="javax.interceptor.api" />

                                    <module name="javax.persistence.api" />

                                    <module name="javax.transaction.api" />

                          </exclusions>

                          <dependencies>

                                    <module name="org.apache.geronimo.specs.geronimo-annotation_1.0_spec" />

                                    <module name="org.apache.geronimo.specs.geronimo-ejb_3.0_spec" />

                                    <module name="org.apache.geronimo.specs.geronimo-interceptor_3.0_spec" />

                                    <module name="org.apache.geronimo.specs.geronimo-jpa_1.0_spec" />

                                    <module name="org.apache.geronimo.specs.geronimo-jta_1.1_spec" />

                                    <module name="org.apache.openjpa" />

                          </dependencies>

                </deployment>

      </jboss-deployment-structure>

       

      persistence.xml:

      <properties>

                ............

                <property name="jboss.as.jpa.providerModule" value="org.apache.openjpa"/>

      </properties>

       

      But on deployment I receive the following stack trace:

       

      11:16:42,439 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-6) MSC00001: Failed to start service jboss.deployment.unit."Project.ear".INSTALL: org.jboss.msc.service.StartException in service jboss.deployment.unit."Project.ear".INSTALL: Failed to process phase INSTALL of deployment "Project.ear"

                at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:121) [jboss-as-server-7.1.0.Alpha2-SNAPSHOT.jar:7.1.0.Alpha2-SNAPSHOT]

                at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1824) [jboss-msc-1.0.1.GA.jar:1.0.1.GA]

                at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1759) [jboss-msc-1.0.1.GA.jar:1.0.1.GA]

                at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) [:1.6.0_26]

                at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) [:1.6.0_26]

                at java.lang.Thread.run(Thread.java:662) [:1.6.0_26]

      Caused by: java.util.ServiceConfigurationError: javax.persistence.spi.PersistenceProvider: Provider org.apache.openjpa.persistence.PersistenceProviderImpl could not be instantiated: java.lang.ClassCastException

                at java.util.ServiceLoader.fail(ServiceLoader.java:207) [:1.6.0_26]

                at java.util.ServiceLoader.access$100(ServiceLoader.java:164) [:1.6.0_26]

                at java.util.ServiceLoader$LazyIterator.next(ServiceLoader.java:353) [:1.6.0_26]

                at java.util.ServiceLoader$1.next(ServiceLoader.java:421) [:1.6.0_26]

                at org.jboss.as.jpa.processor.PersistenceUnitDeploymentProcessor.lookupProvider(PersistenceUnitDeploymentProcessor.java:417)

                at org.jboss.as.jpa.processor.PersistenceUnitDeploymentProcessor.addPuService(PersistenceUnitDeploymentProcessor.java:247)

                at org.jboss.as.jpa.processor.PersistenceUnitDeploymentProcessor.handleEarDeployment(PersistenceUnitDeploymentProcessor.java:194)

                at org.jboss.as.jpa.processor.PersistenceUnitDeploymentProcessor.deploy(PersistenceUnitDeploymentProcessor.java:103)

                at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:115) [jboss-as-server-7.1.0.Alpha2-SNAPSHOT.jar:7.1.0.Alpha2-SNAPSHOT]

                ... 5 more

      Caused by: java.lang.ClassCastException

                at java.lang.Class.cast(Class.java:2990) [:1.6.0_26]

                at java.util.ServiceLoader$LazyIterator.next(ServiceLoader.java:345) [:1.6.0_26]

                ... 11 more

       

       

      Probably this is because of a ClassLoader isolation, maybe I need to exclude more APIs. Is my config ok ?

       

      Thanks,

      Marius

        • 1. Re: JPA 1.0 provider (OpenJPA 1.2.2) on jboss-as-7.1.0.Alpha2-SNAPSHOT result in ClassCastException
          Scott Marlow Master

          Hi Marius,

           

          Is there any more to the exception call stack or does it end as shown above?

           

          Can you try merging your OpenJPA modules, such that you end up with something the following.  This will put them all in one module, which might simplify things.

           

          org.apache.openjpa module:

          <module xmlns="urn:jboss:module:1.0" name="org.apache.openjpa">

            <resources>

              <resource-root path="openjpa-1.2.2.jar"/>

              <resource-root path="geronimo-jpa_1.0_spec-1.1.2.jar"/>

              <!-- ... all of the other geronimo modules should also be inlined here...  -->

            </resources>

           

             <dependencies>

               <module name="javax.api"/>

               <!-- using the AS7 versions of the following modules might also help -->

               <module name="javax.persistence.api"/>

               <module name="javax.transaction.api"/>

               <module name="javax.validation.api"/>

             </dependencies>

          </module>

           

           

          This won't help with the ClassCastException but are you building from AS7 sources or using the nightly build?  If building from sources, you might try adding the openjpa the module list https://github.com/jbossas/jboss-as/commit/0d3f60d42e4ef5e1fbcd65ce3a765e5327f01a05#L0R130 (added a few days ago), so you don't have to specify the ProviderModule property.  It would be good to get this code change in, if you want to submit a patch for the change as well.

           

          Scott

          • 2. Re: JPA 1.0 provider (OpenJPA 1.2.2) on jboss-as-7.1.0.Alpha2-SNAPSHOT result in ClassCastException
            vmariusvv Newbie

            Hi Scott,

             

            It's the whole stack trace.

             

            Using your sugestion, I've passed the  ClassCastException to a new type of problems (ActiveMQ with DuplicateServiceException, problems with DataSources injected with @Resource and JNDI names are prefixed with java:/ even if I specified use-java-context="false").

             

            I'm using the latest nightly build. I'll try to get the sources to see if I can help on this.

             

            Thanks,

            Marius

            • 3. Re: JPA 1.0 provider (OpenJPA 1.2.2) on jboss-as-7.1.0.Alpha2-SNAPSHOT result in ClassCastException
              Scott Marlow Master

              What happens if you change the datasource JNDI name to something like "java:jboss/datasources/YourDSName".

              • 4. Re: JPA 1.0 provider (OpenJPA 1.2.2) on jboss-as-7.1.0.Alpha2-SNAPSHOT result in ClassCastException
                vmariusvv Newbie

                If I put a JNDI like "jdbc/DSName" and use-java-context=true, in the logs I see that "datasources/DSName" was bind to the context but I'm getting an exception when I initialize a object that has @Resource(mappedName = "jdbc/DSName"), something like the injection could not be satisfied (I will try again to show you the exact message). But if I look on the web management interface, I see that my JDBC DS is registered under

                "java:/jdbc/DSName", I hope this is just a bug in the UI when is displaying the JNDI tree.

                 

                If I put JNDI like "java:jboss/datasources/DSName", of course it is registered under "java:jboss/datasources/DSName" and I still have the same error. The problem is that I need to use "jdbc/DSName" to be compatible with another application server.

                 

                 

                Another problem with JNDi seems to be with EJBs, when the server starts I see in the console that my EJB is registered under 6 JNDI names, but not all of them are working. I'm trying to use the simpler one like java:/module/EjbName, but it's not working. In the management interface I see that my EJB is registered only under 2 names, and if I use one of those names, it is working.

                 

                Anyway, this was a thread about OpenJPA and Jboss AS7, maybe we need to move this discussion about JNDI names under another thread and put there all the logs that can help us to see what is the root of this errors.

                • 5. Re: JPA 1.0 provider (OpenJPA 1.2.2) on jboss-as-7.1.0.Alpha2-SNAPSHOT result in ClassCastException
                  Scott Marlow Master

                  Sure, starting a new thread for JNDI name issues is a good idea.  You can link to this thread for related context.

                   

                  Back to the structure of the OpenJPA module(s) on AS7.  I think having one AS7 classloader module is a good start, unless these OpenJPA jars need to be isolated from each other.