Paul Sturrock wrote:
That won't matter. Both styles are valid syntax.
WITH is not an HQL keyword. Have you tried having?
org.springframework.dao.InvalidDataAccessResourceUsageException: could not execute query;
nested exception is org.hibernate.exception.SQLGrammarException: could not execute query
(It needs Group By)
There is a huge difference in using "left join" and "left join fetch".
1. "Left join" --->
Instead of a List of Items, this query returns a List of Object arrays. At index 0 is the Item, and at index 1 is the Bid. A particular Item may appear multiple times, once for each associated Bid.
These duplicate items are duplicate in-memory references, not duplicate instances!
2. "left join fetch" ---> This is also known as eager dynamic fetching.
When executed, it returns a list of Item instances, with their bids collections fully initialized. This is quite different if you compare it to the ordered pairs returned by the queries in the previous section!
The corresponding generated SQL will be:
An additional WITH clause wouldn’t make sense here. You can’t restrict the Bid instances: All the collections must be fully initialized.
Personally I don’t agree with author and hibernate team that WITH clause doesn’t make any sense here… Why I am bound to get all the collections? What if I want only those bids whose
Amount >100 ?