Join and join fetch are two different things. Don't confuse them! Join is taken from the join concept of SQL. Objects to be joined usually appear in other clauses such as select and where. Because the purpose of join is to process the objects to be joined, such as filtering.
Fetch is the capture policy! It indicates which associated objects of the root entity will be loaded together when the entity is loaded! Therefore, the fetch object generally has no alias (aliases must be used if you need to further capture the associated objects of a single element in the set), because it does not return directly with the query result, they will not be filtered in the WHERE clause. They are obtained through the returned root entity navigation!
Fetch should not be shared with setmaxresults () or setfirstresult () because these operations are based on the result set and may contain duplicate data when pre-capturing the collection class, that is to say, you cannot know the exact number of rows in advance.
Fetch cannot be used with an independent with condition. You can create cartesian products by fetch multiple sets in one query. Therefore, pay attention to this.
For bag ing, the join fetch multiple set roles may give unexpected results in some cases, so be careful. Finally, it is meaningless to use full join fetch and right join fetch.
Large collections cannot be loaded at one time! Their preparation should be: lazy must be true! Dynamic crawling should not be captured! Currently, you can only provide additional interfaces to obtain sets in batches. For example, Forum. getthreads (INT firstthreadindex, int threadcount)
Two examples of join and fetch
To filter duplicate objects in join and fetch, you can use either of the following methods:
1. encapsulate the sequencer into set. For example: Set nodupes = new javashashset (resultlist ))
2. Use distinct. For example, select distinct I from item I join fetch I. Bids