Do a paging function.
You need to know how many data can be calculated.
Do you really want session.createQuery (“from ItemInfo”).List ().Size ()?
I’m just implementing such a pagination. To query its list?? is it inefficient?
1.String hql = “select count(*) from table_name”
2.Query query = session.createQuery(hql)
3.int count = Integer.parseInt(query.list().get(0).toString())
Query the total number of entries instead of all the data
The amount of data is sure to be low, and it’s easy to have problems, such as memory overflow, hibernate API provides statistical functions, or SQL (HQL) can be written by yourself.
hibernateIt has built-in paging query function, and does not need to write paging SQL statements automatically.
The subject of the proposal is to be looked at
query.setMaxResults();The efficiency of the method is higher than that of the self written SQL and is easy to use.
My side is used to judge whether pageSize is null or not.
query.setMaxResults();Two paging methods.
If you want to get the number of all records, do not execute paging method, that is, pageSize null.