Cannot simultaneously fetch multiple bags

Source: Internet
Author: User

When did the problem arise?
When an entity object contains more than one non-lazy fetch policy, such as @onetomany, @ManyToMany, or @elementcollection, the fetch policy is (fetch = Fetchtype.eager)

Why the problem occurred:
When (fetch = Fetchtype.eager) is redundant, the persistent framework grabs one side of the object, while the objects of the multi-party are loaded into the container, and multiple parties may be associated with other objects, Hibernate implements the JPA, the default maximum crawl depth with its own level of four level ( It has a property configuration is 0-3), if the multiple (second level) there is a duplicate value, the third level of the crawled value can not be mapped, there will be multiple bags.

Workaround:
1. Change (fetch = Fetchtype.eager) to (fetch = Fetchtype.lazy)
2, the list is modified into a set set, that is, the recommended @manytomany or @onetomany many party at this time with a set container to store, instead of a list collection.
3. Change Fetchmode to @fetch (Fetchmode.subselect), that is, send another SELECT statement to fetch the associated entities of all the entity objects previously queried.
4. Add @indexcolumn to the corresponding attribute, which allows you to indicate the field where the index value is stored, in the same way that the set container does not allow repeating elements.

Recommended treatment: Method 2;
Method 3 and Method 4 are hibernate-specific, non-JPA standards;
If you can use Method 1, then this problem will not occur.

Cannot simultaneously fetch multiple bags

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.