2 Replies Latest reply on Dec 1, 2003 6:36 AM by Wouter Zoons

    ql and COUNT() - return type ?

    nefilim Newbie

      Hi,

      I don't know if this is the best way to do it but I figured it's less expensive to have a select method in the home interface of a cmp that counts the amount of rows for a specific condition than to find them all and count the collection.

      The problem is though, according to Denniger & Peter's EJB 2.1 select methods can only return type of remote or local interface or of a persistent attribute. So I come up with this query:

      SELECT COUNT(p.id) FROM User AS p WHERE p.deptId=?1

      However, deploying on JBoss 3.2.2 I get the following error:

      (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> ...
      )

      Is COUNT() not supported yet or am I not using it correctly? Btw, what does one do if the primary key is not numeric, the return type would not match the persistent attribute type? Is there a better way of achieving this?

      Many thanks,
      Peter