1 2 Previous Next 15 Replies Latest reply on Jun 13, 2013 6:28 AM by Scott Marlow

    JBoss 7 - JPA loading wrong module slot

    Rafael Vanderlei de Souza Newbie

      Hello, everyone.

       

      I have two applications which use different versions of EclipseLink.

       

      I installed version 1.2.0 under {JBOSS}/modules/org/eclipse/persistence/main and version 1.0.1 under {JBOSS}/modules/org/eclipse/persistence/1.0.1.

       

      Then, in jboss-deployment-structure.xml of application A, that uses version 1.2.0, I declare the dependency as <module name="org.eclipse.persistence" />.

      While in application B, that uses version 1.0.1, I declare <module name="org.eclipse.persistence" slot="1.0.1" />.

       

      So, I expected JBoss to load 'main slot' for app A and '1.0.1' slot for app B, but in both cases, JBoss is loading 'main slot'. For some reason, the slot ="1.0.1" is being ignored for app B.

       

      I believe modules configuration (on the server) and dependency declaration (on the app) are correctly set, as you can see below.

       

      Module 1.2.0 (under {JBOSS}/modules/org/eclipse/persistence/main):

      <module xmlns="urn:jboss:module:1.0" name="org.eclipse.persistence">

          <resources>

              <resource-root path="eclipselink-1.2.0.jar"/>

          </resources>

          <dependencies>

              <module name="javax.api"/>

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

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

              <module name="com.oracle.ojdbc14dms"/>

          </dependencies>

      </module>

       

      jboss-deployment-structure.xml for app A:

      <jboss-deployment-structure>

          <deployment>

              <dependencies>

                  <module name="org.eclipse.persistence" />

              </dependencies>

          </deployment>

          <sub-deployment name="jpamodule.jar">

              <dependencies>

                  <module name="org.eclipse.persistence" />

              </dependencies>

          </sub-deployment>

      </jboss-deployment-structure>

       

      Module 1.0.1 (under {JBOSS}/modules/org/eclipse/persistence/1.0.1.):

      <module xmlns="urn:jboss:module:1.0" name="org.eclipse.persistence" slot="1.0.1">

      <resources>

      <resource-root path="eclipselink-1.0.1.jar"/>

      </resources>

      <dependencies>

      <module name="javax.api"/>

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

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

      <module name="com.oracle.ojdbc14dms"/>

      </dependencies>

      </module>

       

      jboss-deployment-structure.xml for app B:

      <jboss-deployment-structure>

          <deployment>

              <exclusions>

                  <module name="org.eclipse.persistence" />

              </exclusions>

              <dependencies>

                  <module name="org.eclipse.persistence" slot="1.0.1"/>

              </dependencies>

          </deployment>

          <sub-deployment name="jpamodule.jar">

              <exclusions>

                  <module name="org.eclipse.persistence" />

              </exclusions>

              <dependencies>

                  <module name="org.eclipse.persistence" slot="1.0.1"/>

              </dependencies>

          </sub-deployment>

      </jboss-deployment-structure>

       

       

      Am I missing something? Or is it a known issue (if so, is there a workaround? )

       

      Regards,

      Rafael.

       

      Message was edited by: jaikiran pai - Edited subject from "JBoss 7 loading wrong module slot" to "JBoss 7 - JPA loading wrong module slot"

        • 1. Re: JBoss 7 loading wrong module slot
          Wolf-Dieter Fink Master

          Which exact version do you use?

          Could you try it with an WildFly nightly build?

          • 2. Re: JBoss 7 loading wrong module slot
            Rafael Vanderlei de Souza Newbie

            Sorry, I forgot to mention it.. I'm using JBoss 7.1.1.Final

             

            I'll try it with WildFly just for curiosity because I'm limited at using JBoss 7.1.1.Final

            • 3. Re: JBoss 7 loading wrong module slot
              jaikiran pai Master

              Out of curiosity, how did you verify it's loading only the main module? For example, have to tried using a slot="2.3.4" in the jboss-deployment-structure.xml just to see if it's being ignored or such?

              • 4. Re: JBoss 7 loading wrong module slot
                Rafael Vanderlei de Souza Newbie

                Hi, jaikiran.

                 

                First, let me just fix some information. I said that I installed version 1.2.0 at "main slot" and version 1.0.1 at slot="1.0.1", but it was the opposite (main slot has version 1.0.1 and slot="1.2.0" has version 1.2.0). The same information fix applies to module dependency declaration in the jboss-deployment-structure.xml (i.e., app that depends on version 1.0.1 declares slot="main" and app that depends on version 1.2.0 declares slot="1.2.0")

                 

                That being said, now answering your question... I verified JBoss is not loading the proper module because when I attempt to call a method in EJB in app that depends on version 1.2.0, JBoss attempts to create EntityManager to inject in EJB, and then I see this entry in log file:

                 

                Exception Description: Attempted to deploy PersistenceUnit [xxx] while being in the wrong state [DeployFailed]. Close all factories for this PersistenceUnit.

                javax.persistence.PersistenceException: Exception [EclipseLink-28013] (Eclipse Persistence Services - 1.0.1 (Build 20080905)): org.eclipse.persistence.exceptions.EntityManagerSetupException

                Exception Description: Attempted to deploy PersistenceUnit [xxx] while being in the wrong state [DeployFailed]. Close all factories for this PersistenceUnit.

                    at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:185)

                    at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.getServerSession(EntityManagerFactoryImpl.java:69)

                    at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManagerImpl(EntityManagerFactoryImpl.java:118)

                    at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManagerImpl(EntityManagerFactoryImpl.java:112)

                    at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:100)

                    at org.jboss.as.jpa.container.EntityManagerUtil.createEntityManager(EntityManagerUtil.java:44)

                    at org.jboss.as.jpa.container.TransactionScopedEntityManager.getEntityManager(TransactionScopedEntityManager.java:75)

                    at org.jboss.as.jpa.container.AbstractEntityManager.createNamedQuery(AbstractEntityManager.java:355)

                 

                So, the app declares dependency on slot="1.2.0" but the log indicates it's using 1.0.1 version, that is installed on slot="main". Also, if I install version 1.2.0 on slot="main", everything works fine to this app, but it breaks the other app that depends on version 1.0.1.

                 

                About you other question, I haven't tried installing slot="2.3.4" yet.. if you think its worth it, I can give it a try.

                • 5. Re: JBoss 7 loading wrong module slot
                  Rafael Vanderlei de Souza Newbie

                  Hi, Wolf.

                   

                  As you asked, I tested in wildfly-8.0.0.Alpha2-SNAPSHOT (downloaded yesterday from https://ci.jboss.org/hudson/job/WildFly-latest-master/lastSuccessfulBuild/artifact/build/target/)

                   

                  And I got the same behaviour, WildFly attempted to use version 1.0.1 (installed as the main slot), instead of using version 1.2.0 (declared in the app's jboss-deployment-structure.xml)

                   

                  And the exception had similar stacktrace from the one I posted previously to jaikiran:

                   

                  javax.persistence.PersistenceException: Exception [EclipseLink-28019] (Eclipse Persistence Services - 1.0.1 (Build 20080905)): org.eclipse.persistence.exceptions.EntityManagerSetupException

                  Exception Description: Deployment of PersistenceUnit [xxx] failed.

                  Internal Exception: java.lang.NullPointerException

                       at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:227)

                       at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.getServerSession(EntityManagerFactoryImpl.java:69)

                       at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManagerImpl(EntityManagerFactoryImpl.java:118)

                       at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManagerImpl(EntityManagerFactoryImpl.java:112)

                       at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:100)

                       at org.jboss.as.jpa.container.TransactionScopedEntityManager.createEntityManager(TransactionScopedEntityManager.java:181)

                       at org.jboss.as.jpa.container.TransactionScopedEntityManager.getEntityManager(TransactionScopedEntityManager.java:83)

                       at org.jboss.as.jpa.container.AbstractEntityManager.createNamedQuery(AbstractEntityManager.java:361)

                   

                  Also, if I install version 1.2.0 in main slot (and change declaration in the app's jboss-deployment-structure.xml to remove slot="1.2.0"), application works fine.

                  • 6. Re: JBoss 7 loading wrong module slot
                    Rafael Vanderlei de Souza Newbie

                    Guys, are you still looking into this? Do you need any more information? If you need and wish, I can provide a EAR and the EclipseLink modules I have installed, to help you reproduce and maybe understand what is going on.

                    • 7. Re: JBoss 7 loading wrong module slot
                      Nicklas Karlsson Master

                      Can you check if this also happens with a non-EE-provider module (some simple jar)?

                      • 8. Re: JBoss 7 loading wrong module slot
                        Rafael Vanderlei de Souza Newbie

                        Hi, Nicklas.

                         

                        As you suggested, I tested with a non-EE-provider module (some simple jar) and everything worked fine.

                         

                        That's what I did to check:

                         

                        I installed a simple.jar under {JBOSS}/modules/com/simple/main

                        - simple.jar has a Simple class with a printSimple() method that prints "Simple for main module" to the console.

                         

                        And installed simple-2.0.jar under {JBOSS}/modules/com/simple/2.0

                        - simple-2.0.jar has a Simple class with a printSimple() method that prints "Simple for 2.0 module" to the console.

                         

                        Then in app-A's jboss-deployment-structure.xml I declared <module name="com.simple" /> then invoked printSimple() and "Simple for main module" was printed to the console.

                         

                        Then in app-B's jboss-deployment-structure.xml I declared <module name="com.simple" slot="2.0"/> then invoked printSimple() and "Simple for 2.0 module" was printed to the console.

                         

                        Also, I have apps that use different versions of Hibernate and JSF installed as modules and they work ok..

                         

                        So, until now, I'm only having problem with EclipseLink module.

                        • 9. Re: JBoss 7 loading wrong module slot
                          jaikiran pai Master

                          This doesn't look like a Modules issue but more of JPA integration issue. From what I gather it looks like the JPA integration code just uses the "main" module slot while loading a persistence provider that's mentioned in the persistence.xml. A quick look at the documentation https://docs.jboss.org/author/display/AS71/JPA+Reference+Guide doesn't show how to setup a slot if at all it can be done.

                          • 10. Re: JBoss 7 loading wrong module slot
                            jaikiran pai Master

                            jaikiran pai wrote:

                             

                            A quick look at the documentation https://docs.jboss.org/author/display/AS71/JPA+Reference+Guide doesn't show how to setup a slot if at all it can be done.

                            Ah nevermind, I just noticed that it does allowing setting the slot like this for example:

                             

                            <properties>
                                        <property name="jboss.as.jpa.providerModule" value="org.hibernate:3" />
                                    </properties>
                            

                             

                            So the value is <modulename>:<slot>. What does your persistence.xml look like?

                            • 11. Re: JBoss 7 loading wrong module slot
                              Rafael Vanderlei de Souza Newbie

                              Jaikiran, thanks for your reply.

                               

                              You shot right on the target. The point I was missing was this property "jboss.as.jpa.providerModule" in the persistence.xml. Setting it to "org.eclipse.persistence:1.2.0" fixed the problem.

                               

                              But I have a consideration to make and I think you may agree with it. (please understand I'm not complaining and I'm just sending you a constructive feedback about the documentation)

                               

                              I had already read before this "JPA Reference Guide" section of AS 7 documentation (as I said before, I have 2 applications that use differente versions of Hibernate working fine.. because there I have "jboss.as.jpa.providerModule" property properly set in the persistence.xml)

                               

                              But just as before and even reading it now again after you pointed it, I think it's not exactly clear (in the documentarion) that this property should be applied for any JPA Provider. Actually I think the documentation leads readers to understand it's a jboss specific property to be set for Hibernate specific JPA provider.. a property that should be configured to allow users to change Hibernate version from 4.x to 3.5x or greater 3.x version (and also to allow use Hibernate jars bundled in EAR).

                               

                              I thinks it's so true, that even you, in a first and for a quick moment, came to the conclusion that "the JPA reference guide doesn't show how to set up a slot if at all it can be done".

                               

                              Well, anyway, many many thanks for taking the time to read the documentation and point me to review my persistence.xml, which solved the problem.

                               

                              I have another question regarding a similar matter. I would open another topic, but as discussion came to this point, I think it makes sense to post the question here. I'll leave it to my next post.

                               

                              Regards,

                              Rafael.

                              • 12. Re: JBoss 7 loading wrong module slot
                                Rafael Vanderlei de Souza Newbie

                                As I said before, I have an application that uses Hibernate 3.3.0.GA, but reading the AS documentation I understand JBoss only supports Hibernate 3.5 or greater versions.

                                 

                                In fact, I have attempted to follow documentation instructions to try using Hibernate 3.3.0.GA in JBoss 7and it didn't work. It really worked only with 3.5 and 3.6 (I tried 3.3, 3.4, 3.5 and 3.6).

                                 

                                To test it, I created a very simple EAR, with just a EJB module that has only the persistence.xml and I made 2 attempts to use Hibernate 3.3.0GA, one installing it as a JBoss Module and other trying to use it bundled in the EAR. And that's the behaviour I had:

                                 

                                1. Using it as a module: JBoss doesn't find classes of Module "org.jboss.as.jpa.hibernate:3", as I receive exceptions like this:

                                 

                                java.lang.ClassNotFoundException: org.jboss.as.jpa.hibernate3.infinispan.SharedInfinispanRegionFactory from [Module "org.jboss.as.jpa.hibernate:3" from local module loader @8b819f (roots: C:\dev\jboss\jboss-as-7.1.1.Final\modules)]

                                 

                                2. Using it bundled in EAR: even setting "jboss.as.jpa.providerModule" to "hibernate3-bundled", JBoss loads Hibernate 4 that comes packaged in AS (in ${JBOSS}/modules/org/hibernate/main). I check this because in the server.log I receive entries like this:

                                 

                                10:15:38,693 INFO  [org.hibernate.Version] (MSC service thread 1-4) HHH000412: Hibernate Core {4.0.1.Final}

                                 

                                Still on attempt #2, because of this, there are classpath conflicts between Hibernate classes loaded from JBoss module and Hibernate classes that I bundled in EAR, as I see in the log some ClassCastException that would not make sense such as java.lang.ClassCastException: org.hibernate.dialect.Oracle10gDialect cannot be cast to org.hibernate.dialect.Dialect (since Oracle10gDialect implements Dialect).

                                 

                                 

                                So, I came to the conclusion that there is really no "out-of-the-box" compatibility between Hibernate 3.3 and JBoss 7.1.1, but I don't understand, and after all this long post, this is what my question is about:

                                 

                                Hibernate 3.5 or higher versions are supported because of some integration written on JBoss AS code or is it something written on Hibernate code? I'm asking this to understand where should I look at if I were about to write a patch to make an application with Hibernate 3.3 to work on JBoss AS 7.

                                 

                                Thanks,

                                Rafael.

                                 

                                Edit: By the way, if someone is curious about how the problems look like, I could share this simple app, the Hibernate modules I installed and a quick guide with the steps to reproduce the errors.. it´s really easy to reproduce.

                                • 13. Re: JBoss 7 loading wrong module slot
                                  jaikiran pai Master

                                  I've update the subject of this thread to make it more relevant to the discussion.

                                  • 14. Re: JBoss 7 loading wrong module slot
                                    Scott Marlow Master

                                    Keep in mind that the documentation link and AS 7.1.x bits, aren't the latest available.  The https://docs.jboss.org/author/display/AS72/JPA+Reference+Guide goes with AS 7.2 (corresponds to the EAP 6.x download).

                                     

                                    We are working on improvements for working with different versions of Hibernate (as well as EclipseLink) in WildFly 8.

                                    1 2 Previous Next