4 Replies Latest reply on Aug 16, 2007 4:55 PM by Tony Mai

    How to use EntityManager for SELECT COUNT(1)?

    Tony Mai Apprentice

      First I'd like to apologize for posting a persistence question on this board. I've tried other boards but no one's home. I am desperate :-(

      I would like to perform a SELECT COUNT(1) FROM a table "TableA" but can't seem to get the SQL statement to work with EntityManager. The following code always return a 0 even I know the table contains hundreds of records.

      int rowCnt= (Integer) em.createQuery("SELECT count(1) FROM TableA").getSingleResult();


      Can anyone help?

      I am using JBoss 4.2.1 with Seam 1.2.1. Thanks.
      -tony