很多方法
比如这样一个持久化对象,id是主键
public class Com {
String id;
String name;
//省略set get
{
1.select count(id) from Com
2.select count(c) from Com c
3.
Session session = //得到一个org.hibernate.Session
Query query = session.createQuery("from Com");
ScrollableResults scrollableResults = query.scroll(ScrollMode.SCROLL_SENSITIVE);
scrollableResults.last();
//rowNumber从0开始,为空时则为-1,因此计算totalCount时应+1
int totalCount = scrollableResults.getRowNumber() + 1;
放你妈的屁,能强转????
query("select count(*) from info where info.id in(?,?,?)");
个人建议,如果用HQL搞不定。可以用简单的SQL搞定。
querySQL(SQL语句);
获取表中的记录也可以用count的。语句如下:
Session session=this.getSession;
string hql="select count(tb) from table tb";
Query query=session.createQuery(hql);
int count=(Integer)query.uniqueResult();