Article From:

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?

Answer 0:

1.String hql = “select count(*) from table_name”
2.Query query = session.createQuery(hql) count = Integer.parseInt(query.list().get(0).toString())
Query the total number of entries instead of all the data

Answer 1:

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.

Answer 2:

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.

Answer 3:

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.

Leave a Reply

Your email address will not be published. Required fields are marked *