List and iterate differences in HQL statements in hibernate

Source: Internet
Author: User

1. Use the list () method to get the results of the query, issuing a statement each time to get all the data.
2. Use the iterate () method to get the results of the query, first issue an SQL statement to query the ID that satisfies the condition data, and then follow these IDs to query the records, that is, to execute the N+1 SQL statement (n is the number of records that match the criteria)

Two execution of the list () method, each execution is issued an SQL statement, query all data.
Here's a look at the output of the two execution iterate () method
Two execution of the iterate () method, the first execution of the N+1 SQL statement issued, and the second execution, only a set of SQL statements, and the first execution of the list () method after the execution of the iterate () method is consistent. This is due to the fact that Hibernate's cache
The 1.list () method will not read the data in the cache, it always queries the eligible data directly from the database at once, and writes the obtained data to the cache.
The 2.iterate () method is to obtain the ID of the eligible data, first, based on the ID in the cache to find matching data, if the cache does not meet the criteria of the data, and then query the database

List and iterate differences in HQL statements in hibernate

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.