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