8 Replies Latest reply on Jul 11, 2012 3:34 PM by endrigoantonini

    Named query not found in JBoss AS 7

    dmitriy_fot

      Im in process of migrating a big JEE application from JBoss AS 4 to JBoss AS 7.

       

      After resolving this packaging issue: http://community.jboss.org/message/636897#636897

      and resolving some other JNDI naming problems,

      my next challenge is server not being able to find the named queries in the entities.

       

      EXCEPTION:

       

      javax.ejb.EJBException: java.lang.IllegalArgumentException: Named query not found: com.mmffa.ffmms.ejb.Global.find0

       

       

       

      INVOCATION:

       

      static Global findByPrimaryKey(Integer id)

              throws NotFoundException

          {

              EntityManager entityManager = getEntityManager();

              Query query = entityManager.createNamedQuery(

                      "com.mmffa.ffmms.ejb.Global.find0");

       

       

       

      DECLARATION of the Entity is the following:

       

      @NamedQueries({

          /**

       

           * Retrieves a {@link Global} by its primary key.

       

           *

       

           */

       

          @NamedQuery(name="com.mmffa.ffmms.ejb.Global.find0", query="SELECT " +

       

                  "OBJECT(global) FROM ffmms_globals global WHERE global.id = ?1")

      })

       

      @Entity(name="ffmms_globals")

      @Table(name="ffmms_globals")

      public class GlobalBean {

      ...

      }

        • 1. Re: Named query not found in JBoss AS 7
          dmitriy_fot

          The issue was resolved by fixing the path in persistence.xml file. The required files simple were not scanned by the entity scanner.

          • 2. Re: Named query not found in JBoss AS 7
            jsebfranck

            Hi,

             

            Could you please give more details about the path you fixed?

             

            Thank you in advance.

            • 3. Re: Named query not found in JBoss AS 7
              endrigoantonini

              Hi,

               

              Can you give more details how did you fixed that?

               

              I'm having the same thing!

               

              Regards!

              • 4. Re: Named query not found in JBoss AS 7
                jsebfranck

                If your persistence.xml file is not in the same jar than your EJB entities, the property jar-file of your persistence.xml file must refer the EJB entities jar. But if the persistence.xml file is in the same module than your EJB entities, this property is not required.

                 

                A working example of EJB entities and persistence.xml packaged in the same war (so without the jar-file property)  :

                 

                /WEB-INF/classes/META-INF/persistence.xml :

                 

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

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

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

                        version="2.0">

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

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

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

                        <properties>

                            <property name="hibernate.hbm2ddl.auto" value="none" />

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

                        </properties>

                    </persistence-unit>

                </persistence>

                 

                With entity .class file packaged in WEB-INF/classes.

                • 5. Re: Named query not found in JBoss AS 7
                  dmitriy_fot

                  Sorry, for belayed response.

                   

                  Frankly, I don't remember the solution for this exact problem. I had multiple problems with persistence.xml while switching from JBoss 4 to JBoss 7, and all of them were resolved by the following steps:

                   

                  1. move persistence.xml from ejb.jar to the utility jar of the same EAR application,

                   

                  2. persistence.xml has references to all the ejb-jars with JPA entities, it looks like this:

                   

                  <jta-data-source>java:/DefaultDS</jta-data-source>

                  <jar-file>../fms-ejb.jar</jar-file>

                  <jar-file>../frstl-ejb.jar</jar-file>

                  <jar-file>../default-ejb.jar</jar-file>

                  • 6. Re: Named query not found in JBoss AS 7
                    endrigoantonini

                    @jsebfranck and @Dmitriy Fot

                     

                    Thanks for your answer.

                    I have a little more complicated situation.

                    I use a war deployment, and inside it, there is the META-INF/persistence.xml.

                     

                    The funny stuff is that the JBoss (I'm using the 7.1.1) can find it and start the persistence.xml and the Hibernate.

                    If I use Criteria (from JPA or Hibernate) there's no problem!

                     

                    If I try to use a NamedQuery that is declared on a bean, I receive the same exception that is on the first post.

                     

                    Here is the stack trace:

                    09:35:49,396 ERROR [SomeClass] (MSC service thread 1-7) Named query not found: User.findByEmailConstraint: java.lang.IllegalArgumentException: Named query not found: User.findByEmailConstraint

                            at org.hibernate.ejb.AbstractEntityManagerImpl.createNamedQuery(AbstractEntityManagerImpl.java:647) [hibernate-entitymanager-4.1.4.Final.jar:4.1.4.Final]

                            at company.credential.permission.dao.UserDAO.findUserByEmail(UserDAO.java:78) [classes:1.3.5]

                            at company.credential.permission.UserBO.findUserByEmail(UserBO.java:125) [classes:1.3.5]

                            at company.module.web.context.DatabaseDumpBO.checkAndDumpUser(DatabaseDumpBO.java:168) [classes:1.3.5]

                            at company.module.web.context.DatabaseDumpBO.checkDatabaseAndDump(DatabaseDumpBO.java:53) [classes:1.3.5]

                            at company.module.web.context.WebContextListener.contextInitialized(WebContextListener.java:31) [classes:1.3.5]

                            at org.apache.catalina.core.StandardContext.contextListenerStart(StandardContext.java:3392) [jbossweb-7.0.13.Final.jar:]

                            at org.apache.catalina.core.StandardContext.start(StandardContext.java:3850) [jbossweb-7.0.13.Final.jar:]

                            at org.jboss.as.web.deployment.WebDeploymentService.start(WebDeploymentService.java:90) [jboss-as-web-7.1.1.Final.jar:7.1.1.Final]

                            at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811)

                            at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746)

                            at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110) [rt.jar:1.7.0_04]

                            at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603) [rt.jar:1.7.0_04]

                            at java.lang.Thread.run(Thread.java:722) [rt.jar:1.7.0_04]

                     

                    Important thing's:

                    I updated the Hibernate that is on the JBoss 7.1.1 to the 4.1.4 version; (My application was developed and compiled using it);

                     

                    Environment:

                    JBoss 7.1.1 (Hibernate updated);

                    JDK 7 update 04;

                    • 7. Re: Named query not found in JBoss AS 7
                      jsebfranck

                      If your persistence.xml file is in the WEB-INF/classes/META-INF directory and your entities are in WEB-INF/classes directory according to the specs, it should work. You can try either with a jboss 7.1.1 without trying to update hibernate, or wait jboss 7.2 alpha (mid july), or attach your web application to this thread so I could take a look.

                      • 8. Re: Named query not found in JBoss AS 7
                        endrigoantonini

                        I created a foo project based on the things i've done on my main project.

                         

                        I runned that war on my JBoss 7.1.1 (that I updated the hibernate to the 4.1.4 version) and had the same error.

                        Here are the war file and the source if someone want to find some mistake.

                         

                        Here is what I receive on my console:

                         

                        16:25:06,811 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/teste-jboss]] (MSC service thread 1-7) Exception sending context initialized event to listener instance of class com.example.entity.FooEntityListener: java.lang.IllegalArgumentException: Named query not found: FooEntity.findByParam

                                at org.hibernate.ejb.AbstractEntityManagerImpl.createNamedQuery(AbstractEntityManagerImpl.java:647) [hibernate-entitymanager-4.1.4.Final.jar:4.1.4.Final]

                                at com.example.entity.FooEntityDAO.findByParam(FooEntityDAO.java:21) [classes:]

                                at com.example.entity.FooEntityListener.contextInitialized(FooEntityListener.java:18) [classes:]

                                at org.apache.catalina.core.StandardContext.contextListenerStart(StandardContext.java:3392) [jbossweb-7.0.13.Final.jar:]

                                at org.apache.catalina.core.StandardContext.start(StandardContext.java:3850) [jbossweb-7.0.13.Final.jar:]

                                at org.jboss.as.web.deployment.WebDeploymentService.start(WebDeploymentService.java:90) [jboss-as-web-7.1.1.Final.jar:7.1.1.Final]

                                at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811)

                                at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746)

                                at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110) [rt.jar:1.7.0_04]

                                at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603) [rt.jar:1.7.0_04]

                                at java.lang.Thread.run(Thread.java:722) [rt.jar:1.7.0_04]

                         

                         

                        16:25:06,885 ERROR [org.apache.catalina.core.StandardContext] (MSC service thread 1-7) Error listenerStart

                        16:25:06,886 ERROR [org.apache.catalina.core.StandardContext] (MSC service thread 1-7) Context [/teste-jboss] startup failed due to previous errors

                        16:25:06,903 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-7) MSC00001: Failed to start service jboss.web.deployment.default-host./teste-jboss: org.jboss.msc.service.StartException in service jboss.web.deployment.default-host./teste-jboss: JBAS018040: Failed to start context

                                at org.jboss.as.web.deployment.WebDeploymentService.start(WebDeploymentService.java:95)

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

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

                                at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110) [rt.jar:1.7.0_04]

                                at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603) [rt.jar:1.7.0_04]

                                at java.lang.Thread.run(Thread.java:722) [rt.jar:1.7.0_04]

                         

                         

                        16:25:07,124 INFO  [org.jboss.as.server] (DeploymentScanner-threads - 2) JBAS015870: Deploy of deployment "teste-jboss.war" was rolled back with failure message {"JBAS014671: Failed services" => {"jboss.web.deployment.default-host./teste-jboss" => "org.jboss.msc.service.StartException in service jboss.web.deployment.default-host./teste-jboss: JBAS018040: Failed to start context"}}

                        16:25:07,129 INFO  [org.jboss.as.jpa] (MSC service thread 1-2) JBAS011403: Stopping Persistence Unit Service 'teste-jboss.war#persistenceUnit'

                        16:25:07,179 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-2) JBAS015877: Stopped deployment teste-jboss.war in 54ms

                        16:25:07,180 INFO  [org.jboss.as.controller] (DeploymentScanner-threads - 2) JBAS014774: Service status report

                        JBAS014777:   Services which failed to start:      service jboss.web.deployment.default-host./teste-jboss: org.jboss.msc.service.StartException in service jboss.web.deployment.default-host./teste-jboss: JBAS018040: Failed to start context

                         

                         

                        16:25:07,185 ERROR [org.jboss.as.server.deployment.scanner] (DeploymentScanner-threads - 1) {"JBAS014653: Composite operation failed and was rolled back. Steps that failed:" => {"Operation step-2" => {"JBAS014671: Failed services" => {"jboss.web.deployment.default-host./teste-jboss" => "org.jboss.msc.service.StartException in service jboss.web.deployment.default-host./teste-jboss: JBAS018040: Failed to start context"}}}}