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