3 Replies Latest reply on Nov 9, 2005 11:57 AM by dornus

    Select count(*) on table with no rows

    dornus Novice

      I have a tbale with no rows in it. I would like to get the count for that table. I would expect to see zero rows returned instead of an error.

       final Query q = em.createNativeQuery(
       "select count(*) " +
       "from MyTable " +
       "where myColumn = :col ", MyClass.class
       );
       q.setParameter("col", myColumnValue);
       return (Integer) q.getSingleResult();
      


      I think this is because it is trying to create a MyClass object, but cannot since no data was returned by the database.

      Is there a better way of doing this?