3 Replies Latest reply on Apr 17, 2013 11:42 PM by nitin_jain

    Mulitiple EJB3.0 JARs on JBoss7.1.3 - Named query not found

    nitin_jain

      Hello Forum,

       

      I am migrating an application from jboss-5.1.0.GA to jboss-eap-6.0.1 (AS 7.1.3.Final-redhat-4).

       

      When the EAR that contains multiple EJB3.0 specific JAR files (each EJB JAR file contains "persistence.xml") is deployed in jboss-5.1.0.GA, the named queries can be invoked successfully. While the deployment of the EAR is successful in jboss-eap-6.0.1, the finder methods invoking named queries fail with the following exception. 

      Caused by: java.lang.IllegalArgumentException: Named query not found: Company.findByName

      at org.hibernate.ejb.AbstractEntityManagerImpl.createNamedQuery(AbstractEntityManagerImpl.java:601)

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

       

       

      Please advise why this exception is happening and what may be a probable solution.

       

      Thank you.

       

      Best Regards,

      Nitin

        • 1. Re: Mulitiple EJB3.0 JARs on JBoss7.1.3 - Named query not found
          wdfink

          Humm,

          Could it be a initialisation order problem?

          You might add the jar's in a correct order and set the flag module-order strict within the jboss-app.xml.

           

          see here

          • 2. Re: Mulitiple EJB3.0 JARs on JBoss7.1.3 - Named query not found
            nitin_jain

            Hello Wolf,

             

            Thank you for your response. I did make the changes in the order in which the 2 EJB jars are deployed; however what I can understand is that the server recognizes the first "persistence.xml" and seems to ignore the second. So if I invoke a finder in the EJB JAR deployed first, the query is executed, but when the finder in second EJB JAR is invoked the named query is not found.

             

            Any other possible solution would be appreciated.

             

            Best Regards,

            Nitin

            • 3. Re: Mulitiple EJB3.0 JARs on JBoss7.1.3 - Named query not found
              nitin_jain

              Hello Forum,

               

              There is a solution to this problem.

               

              EAR Structure - Not working in JBoss 7.1.3 but works in JBoss5.1.0.GA

              my-app.ear

                  META_INF

                      application.xml

                  EJB-1.jar

                      META-INF

                          persistence.xml

                  EJB-2.jar

                      META-INF

                          persistence.xml  

               

              EAR Structure - Working in JBoss 7.1.3

              my-app.ear

                  META_INF

                      application.xml

                      persistence.xml

                  EJB-1.jar

                  EJB-2.jar

               

              Also, there is a change in "persistence.xml".

               

              <?xml version="1.0"?>

              <persistence xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

                  version="2.0" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"

                  xmlns="http://java.sun.com/xml/ns/persistence">

               

                  <persistence-unit name="MY_PU" transaction-type="JTA">

                      <description>Persistence Unit</description>

                      <provider>org.hibernate.ejb.HibernatePersistence</provider>

                      <jta-data-source>java:jboss/datasources/MyDS</jta-data-source>

                      <jar-file>my-app.ear/EJB-1.jar</jar-file>

                      <jar-file>my-app.ear/EJB-2.jar</jar-file>       

                      <properties>

                          <property name="hibernate.show_sql" value="true" />

              ........

                      </properties>

                  </persistence-unit>

              </persistence>

               

              Can anyone reason why such a change is required?

               

              Best Regards,

              Nitin