Join and fetch

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.