Difference between Hibernate-list () and iterate () methods, hibernateiterate
For the list method, Hibernate uses a Select SQL statement to obtain all records. And read it and enter it in POJO to return it.
The iterate method first obtains the IDs of all records that meet the query conditions through a Select SQL statement, and then performs cyclic operations on this id set, use a separate Select SQL statement to retrieve the records corresponding to each id, and enter the records in POJO to return the results.
That is to say, the list operation requires an SQL statement. For iterate operations, n + 1 SQL statement is required.
It seems that the iterate method is redundant, but it still has its unique functions under different circumstances, such as querying massive data. If you use the list method to retrieve the result set once, memory overhead may be unbearable.
On the other hand, for our current Cache mechanism, the list method will not read data from the Cache, and it will always read all the qualified records from the database at a time. Because the iterate method obtains data based on the id each time, this implementation mechanism also provides the possibility to read data from the Cache. hibernate will first find the corresponding data in the local Cache based on this id, if not, search in the database.
Two Query methods: list () and iterate () are used to list the result set. They have three differences,
1: different types are returned. list () returns List, iterate () returns Iterator,
2: The methods for obtaining data are different. list () queries the database directly, and iterate () retrieves IDs from the database first, then, when you really want to traverse an object, first find it in the cache. If you cannot find it, use the id as the condition and then send an SQL statement to the database. In this way, if there is no data in the cache, the number of queries to the database is n + 1.
3: iterate queries Level 2 caches, and list queries Level 1 caches only.
4: each object in the list returned by List () is the original object, and the object returned by iterate () is the proxy object. (this can be found by debug)
What is the difference between iterate and reiterate?
Dictionary interpretation is similar. You can only say that reiterate is more advanced than iterate. You can understand it:
Iterate is repeated
Reiterate is to put it back and forth, with a heavier tone
What is the difference between iterate and reiterate?
Iterate
Tour (verb)
Example: an iterating library tour library
Reiterate
Reiterate, repeat/talk
For example, reiterate one's view