2 Replies Latest reply on Jun 25, 2004 4:14 PM by millerm1

    is count from EJB 2.1 supported

      I was trying to determine if count from EJB 2.1 is supported in JBoss 3.2.3 and if not, then it what version it might be supported. I found some postings that discussed it being supported in 3.2.x but the thread never gave a definitive answer. I searched the forums and wiki and I could not find mention of it.

      I tried it with the following code using xdoclet

       /**
       * @ejb.select
       * query="select count(r) from myNode r where r.isRouter = True and r.status = ?1"
       */
       public abstract int ejbSelectCountStatusRouters(Integer status) throws javax.ejb.FinderException;
      


      This resulted in an exception at deploy time:
      org.jboss.deployment.DeploymentException: Error compiling EJB-QL statement 'select count(r) from myNode r where r.isRouter = True and r.status = ?1'; - nested throwable: (org.jboss.ejb.plugins.cmp.ejbql.ParseException: Encountered "count" at line 1, column 8.
      Was expecting one of:
       "DISTINCT" ...
       "OBJECT" ...
       <NUMERIC_VALUED_PATH> ...
       <STRING_VALUED_PATH> ...
       <DATETIME_VALUED_PATH> ...
       <BOOLEAN_VALUED_PATH> ...
       <ENTITY_VALUED_PATH> ...
       <VALUE_CLASS_VALUED_PATH> ...
       )
       at org.jboss.ejb.plugins.cmp.jdbc.JDBCEJBQLQuery.<init>(JDBCEJBQLQuery.java:50)
       at org.jboss.ejb.plugins.cmp.jdbc.JDBCCommandFactory.createEJBQLQuery(JDBCCommandFactory.java:59)
       at org.jboss.ejb.plugins.cmp.jdbc.JDBCQueryManager.start(JDBCQueryManager.java:212)
       at org.jboss.ejb.plugins.cmp.jdbc.JDBCStoreManager.startStoreManager(JDBCStoreManager.java:490)
       at org.jboss.ejb.plugins.cmp.jdbc.JDBCStoreManager.start(JDBCStoreManager.java:388)
       at org.jboss.ejb.plugins.CMPPersistenceManager.start(CMPPersistenceManager.java:152)
       at org.jboss.ejb.EntityContainer.startService(EntityContainer.java:342)
       at org.jboss.system.ServiceMBeanSupport.start(ServiceMBeanSupport.java:192)
       at sun.reflect.GeneratedMethodAccessor5.invoke(Unknown Source)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
       at java.lang.reflect.Method.invoke(Method.java:324)
       at org.jboss.mx.capability.ReflectedMBeanDispatcher.invoke(ReflectedMBeanDispatcher.java:284)
       at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:546)
       at org.jboss.system.ServiceController$ServiceProxy.invoke(ServiceController.java:976)
       at $Proxy14.start(Unknown Source)
       at org.jboss.system.ServiceController.start(ServiceController.java:394)
       at sun.reflect.GeneratedMethodAccessor6.invoke(Unknown Source)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
       at java.lang.reflect.Method.invoke(Method.java:324)
       at org.jboss.mx.capability.ReflectedMBeanDispatcher.invoke(ReflectedMBeanDispatcher.java:284)
       at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:546)
       at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:177)
       at $Proxy29.start(Unknown Source)
       at org.jboss.ejb.EjbModule.startService(EjbModule.java:331)
       at org.jboss.system.ServiceMBeanSupport.start(ServiceMBeanSupport.java:192)
       at sun.reflect.GeneratedMethodAccessor5.invoke(Unknown Source)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
       at java.lang.reflect.Method.invoke(Method.java:324)
       at org.jboss.mx.capability.ReflectedMBeanDispatcher.invoke(ReflectedMBeanDispatcher.java:284)
       at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:546)
       at org.jboss.system.ServiceController$ServiceProxy.invoke(ServiceController.java:976)
       at $Proxy14.start(Unknown Source)
       at org.jboss.system.ServiceController.start(ServiceController.java:394)
       at sun.reflect.GeneratedMethodAccessor6.invoke(Unknown Source)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
       at java.lang.reflect.Method.invoke(Method.java:324)
       at org.jboss.mx.capability.ReflectedMBeanDispatcher.invoke(ReflectedMBeanDispatcher.java:284)
       at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:546)
       at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:177)
       at $Proxy12.start(Unknown Source)
       at org.jboss.ejb.EJBDeployer.start(EJBDeployer.java:544)
       at org.jboss.deployment.MainDeployer.start(MainDeployer.java:832)
       at org.jboss.deployment.MainDeployer.start(MainDeployer.java:824)
       at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:642)
       at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:605)
       at sun.reflect.GeneratedMethodAccessor41.invoke(Unknown Source)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
       at java.lang.reflect.Method.invoke(Method.java:324)
       at org.jboss.mx.capability.ReflectedMBeanDispatcher.invoke(ReflectedMBeanDispatcher.java:284)
       at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:546)
       at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:177)
       at $Proxy6.deploy(Unknown Source)
       at org.jboss.deployment.scanner.URLDeploymentScanner.deploy(URLDeploymentScanner.java:302)
       at org.jboss.deployment.scanner.URLDeploymentScanner.scan(URLDeploymentScanner.java:476)
       at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.doScan(AbstractDeploymentScanner.java:201)
       at org.jboss.deployment.scanner.AbstractDeploymentScanner.startService(AbstractDeploymentScanner.java:274)
       at org.jboss.system.ServiceMBeanSupport.start(ServiceMBeanSupport.java:192)
       at sun.reflect.GeneratedMethodAccessor5.invoke(Unknown Source)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
       at java.lang.reflect.Method.invoke(Method.java:324)
       at org.jboss.mx.capability.ReflectedMBeanDispatcher.invoke(ReflectedMBeanDispatcher.java:284)
       at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:546)
       at org.jboss.system.ServiceController$ServiceProxy.invoke(ServiceController.java:976)
       at $Proxy0.start(Unknown Source)
       at org.jboss.system.ServiceController.start(ServiceController.java:394)
       at sun.reflect.GeneratedMethodAccessor6.invoke(Unknown Source)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
       at java.lang.reflect.Method.invoke(Method.java:324)
       at org.jboss.mx.capability.ReflectedMBeanDispatcher.invoke(ReflectedMBeanDispatcher.java:284)
       at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:546)
       at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:177)
       at $Proxy4.start(Unknown Source)
       at org.jboss.deployment.SARDeployer.start(SARDeployer.java:226)
       at org.jboss.deployment.MainDeployer.start(MainDeployer.java:832)
       at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:642)
       at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:605)
       at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:589)
       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
       at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
       at java.lang.reflect.Method.invoke(Method.java:324)
       at org.jboss.mx.capability.ReflectedMBeanDispatcher.invoke(ReflectedMBeanDispatcher.java:284)
       at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:546)
       at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:177)
       at $Proxy5.deploy(Unknown Source)
       at org.jboss.system.server.ServerImpl.doStart(ServerImpl.java:384)
       at org.jboss.system.server.ServerImpl.start(ServerImpl.java:291)
       at org.jboss.Main.boot(Main.java:150)
       at org.jboss.Main$1.run(Main.java:395)
       at java.lang.Thread.run(Thread.java:534)
      Caused by: org.jboss.ejb.plugins.cmp.ejbql.ParseException: Encountered "count" at line 1, column 8.
      Was expecting one of:
       "DISTINCT" ...
       "OBJECT" ...
       <NUMERIC_VALUED_PATH> ...
       <STRING_VALUED_PATH> ...
       <DATETIME_VALUED_PATH> ...
       <BOOLEAN_VALUED_PATH> ...
       <ENTITY_VALUED_PATH> ...
       <VALUE_CLASS_VALUED_PATH> ...
      
       at org.jboss.ejb.plugins.cmp.ejbql.EJBQLParser.generateParseException(EJBQLParser.java:3858)
       at org.jboss.ejb.plugins.cmp.ejbql.EJBQLParser.jj_consume_token(EJBQLParser.java:3739)
       at org.jboss.ejb.plugins.cmp.ejbql.EJBQLParser.SelectClause(EJBQLParser.java:335)
       at org.jboss.ejb.plugins.cmp.ejbql.EJBQLParser.EJBQL(EJBQLParser.java:98)
       at org.jboss.ejb.plugins.cmp.ejbql.EJBQLParser.parse(EJBQLParser.java:60)
       at org.jboss.ejb.plugins.cmp.jdbc.JDBCEJBQLCompiler.compileEJBQL(JDBCEJBQLCompiler.java:145)
       at org.jboss.ejb.plugins.cmp.jdbc.JDBCEJBQLQuery.<init>(JDBCEJBQLQuery.java:42)
       ... 89 more
      
      


      Thanks in advance,
      Mark


        • 1. Re: is count from EJB 2.1 supported
          jae77

          you need to "override" the EJBQL statement w/ a JBossQL statement, and then you can retrieve the count.

          • 2. Re: is count from EJB 2.1 supported

            Thank you, I've finally manged to get it to work using overriding jbossql.

            I had a lot of trouble finding any documentation of the syntax or any examples,
            and for any one else doing this there were two issues that I had to figure out.
            First doing the count on the beans like
            select count (r) from myNode r ...
            does not work and gives an exception when it is run, but counting a cmp field
            select count (r.ipHostname) from myNode r ...
            does work.

            The second thing I had to figure out is that count returns a Long.

            Here are the new segments from my working code using xdoclet.

            This was added to the class level tag (seems like it ought to be on the method level tag)

             * @jboss.query
             * signature="java.lang.Long ejbSelectCountStatusRouters(java.lang.Integer status)"
             * query="select count(rout.ipHostname) from myNode rout where rout.isRouter = True and rout.status = ?1"
             *
            


            then the two methods I added: an ejbSelect and an ejbHome:
             /**
             * @ejb.select
             * query="select count(r) from myNode r where r.isRouter = True and r.status = ?1"
             *
             */
             public abstract java.lang.Long ejbSelectCountStatusRouters(java.lang.Integer status) throws javax.ejb.FinderException;
            
             /**
             * @ejb.home-method
             * view-type = "local"
             *
             */
             public Long ejbHomeCountStatusRouters(java.lang.Integer status) throws javax.ejb.FinderException {
             return ejbSelectCountStatusRouters(status);
             }
            


            I hope this helps others,
            Mark