大家好,使用hibernate链接MySQL查询,如果从一个库中查询数量,那么下面这两种方式那个效率好一些?
1,select count(*) from itemresult where itemid=2;
取得count(*)2,from ItemResult where itemId=?
取得List<ItemResult>.size()
1,select count(*) from itemresult where itemid=2;
取得count(*)2,from ItemResult where itemId=?
取得List<ItemResult>.size()
但是 hql 移植比较好一些吧。
这个直接从数据库中获得结果,而第二个方法是查询数据库后再计算结果