2 Replies Latest reply on Dec 4, 2015 1:30 PM by sridhar778

    OpenJPA ManytoOne doesnt load eagerly. Works fine in Websphere Community but not in JBoss EAP 6.3

    sridhar778

      Same OpenJPA version 2.1.1 on both servers. Same Code persistence.xml . Same Mysql database. Same java annotations, but for ManytoOne annotations do not load eagerly on Jboss server whereas it works fine on Websphere Community edition.

      Other JPA functionality is fine on Jboss too.

      Have a "return query.getResultList()" statement with a List as return type for the method.

      EntityA has below ManytoOne.Added fetchtype of Eager eventhough default is Eager for this ManytoOne. Also tried to see if LoadFetchGroup needs to be added. Still did not work.

      Also tried @PrimaryKeyJoinColumn instead of @JoinColumn. Didnt work. @PrimaryKeyJoinColumn(name = "report_status_id", referencedColumnName = "report_status_id")

      Basically, the queries to load the manytoone associations are not getting generated.

       @ManyToOne(optional = false,fetch=FetchType.EAGER) // @LoadFetchGroup("detail") @JoinColumn(name = "report_type_id", referencedColumnName = "report_type_id") private ReportType reportType;  @ManyToOne(optional = false,fetch=FetchType.EAGER) //@ManyToOne(optional = false) @JoinColumn(name = "report_status_id", referencedColumnName = "report_status_id") private ReportStatus reportStatus; ----------- Entity on the other side ReportType has this. Tried with both List return type and Set return type. // @OneToMany(mappedBy = "reportType",fetch=FetchType.EAGER) @OneToMany(mappedBy = "reportType") private Set<ReportFile> reportFileCollection;

      Only way i was able to get it to work was by looping the return List and for each item accessing/printing contents of any of the EntityB/C values. Which means those manytoone entities are being loaded Lazily. This is a Migration project and so do not want to change too much of client code.

      Have even tried below in persistence.xml but no help.

      <property name="openjpa.jdbc.EagerFetchMode" value="parallel"/> <property name="openjpa.jdbc.SubclassFetchMode" value="join"/>

      Bear in mind that code works with no issues on Websphere Community Edition server as is but only doesnt work in Jboss EAP 6.3.

        • 1. Re: OpenJPA ManytoOne doesnt load eagerly. Works fine in Websphere Community but not in JBoss EAP 6.3
          jamezp

          Did you install OpenJPA as a module? By default JBoss EAP uses Hibernate for it's JPA implementation.

           

          --

          James R. Perkins

          • 2. Re: OpenJPA ManytoOne doesnt load eagerly. Works fine in Websphere Community but not in JBoss EAP 6.3
            sridhar778

            James, Thanks for your time.

             

            Iam using Jboss EAP 6.3 and not WildFly. I did install OpenJPA as a module. Steps taken are as below...

             

            1.Create openjpa directory under jboss-eap-6.3\modules\system\layers\base\org\jboss\as\jpa and copy jboss-as-jpa-openjpa-7.2.0.Final.jar in openjpa directory and create a module.xml as below

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

            <module xmlns="urn:jboss:module:1.1" name="org.jboss.as.jpa.openjpa">

                <properties>

                    <property name="jboss.api" value="private"/>

                </properties>

                <resources> 

                    <resource-root path="jboss-as-jpa-openjpa-7.2.0.Final.jar"/>

                    <!-- Insert resources here -->

                </resources>

                <dependencies> 

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

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

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

                    <module name="org.jboss.as.jpa.spi"/> 

                    <module name="org.jboss.logging"/>

                    <module name="org.jboss.jandex"/>

                    <module name="org.apache.openjpa" optional="true"/>  <!-- org.apache.openjpa:main must be created manually with OpenJPA jars --> 

                </dependencies>

            </module>

             

            2.Create openjpa directory under jboss-eap-6.3\modules\system\layers\base\org\apache and copy openjpa-all-2.1.1.jar and serp-1.13.1.jar with a module.xml as below

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

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

                <resources>

              <resource-root path="openjpa-all-2.1.1.jar">

              <filter>

                          <exclude path="javax/**" />

                       </filter>

              </resource-root> 

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

                </resources>

             

                <dependencies>

                    <module name="javax.api"/>

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

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

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

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

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

                    <module name="javax.xml.bind.api"/>

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

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

                    <module name="org.jboss.as.jpa.spi"/>

                    <module name="org.jboss.logging"/>

                    <module name="org.jboss.vfs"/>

                    <module name="org.jboss.jandex"/>

              <module name="org.jboss.logmanager"/>

                    <module name="org.slf4j" />

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

                </dependencies>

            </module>

             

            3.In my persistence.xml, i have <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>

             

            I do see in my logs

             

            11:54:59,049 DEBUG [org.jboss.as.jpa] (MSC service thread 1-3) report is configured to use adapter module 'org.jboss.as.jpa.openjpa'

            11:54:59,049 DEBUG [org.jboss.as.jpa] (MSC service thread 1-3) report is configured to use provider module 'org.apache.openjpa'

            11:54:59,050 DEBUG [org.jboss.as.jpa] (MSC service thread 1-3) added org.jboss.as.jpa.openjpa:main dependency to report.ear

            11:54:59,050 DEBUG [org.jboss.as.jpa] (MSC service thread 1-3) added org.apache.openjpa:main dependency to report.ear

             

            Other Jpa functions seem to be normal as i see expected queried being generated. As of now, i see this issue with ManytoOne NOT being loaded EAGERLY but only LAZILY (queries not getting generated for manytoone associations until they are accessed for the first time)

             

            Any help appreciated....