Hi,
After upgrading to version 4.2.x, I noticed a difference in the way collection batch fetching is handled :
Before 4.2.x, we used the following pattern in a spring web mvc application :
1. Call a transactional service method in a controller to fetch entities to display
2. Add the entities (with lazy collections) in the view model
3. Iterate over the collections in the JSP which triggers the batch fetching of the collections.
Now, since 4.2.0 (commit https://github.com/hibernate/hibernate-orm/commit/2040e44c03455d5f39b90e3548cf7da421e34aaf I believe), when the transaction is commited at the end of the service call, the batchFetchQueue is automatically cleared, disabling batch fetching outside of the transaction boundary (esp. in the view layer). All the collections are now fetched with n+1 selects.
I find this new behaviour to be a bit limiting. If you don't initialize all your collections before the entitymanager flush, you lose the opportunity to batch fetch them later, even if nothing was modified in the database.
|