# MultipleBagFetchException: cannot simultaneously fetch multiple bags [TOC] ###### tags: `hibernate` --- > Fetching two or more Bags at the same time on an Entity could form a Cartesian Product. Since a Bag doesn't have an order, Hibernate would not be able to map the right columns to the right entities. Hence, in this case, it throws a MultipleBagFetchException. ## 解決方案一 在 entity class 的`Collection`attribute 加上 ``` @LazyCollection(LazyCollectionOption.FALSE) ``` 若原本有 ``` @ManyToMany(fetch = FetchType.*) ``` 則另須將`fetch = FetchType.*`拿掉。 出處:[Hibernate throws MultipleBagFetchException - cannot simultaneously fetch multiple bags](https://stackoverflow.com/questions/4334970/hibernate-throws-multiplebagfetchexception-cannot-simultaneously-fetch-multipl) ## 解決方案二 * 將`Collection`改為`Set`。 * 將`Collection`改為`List`。 * 使用 multiple queries (建議)。 出處:[A Guide to MultipleBagFetchException in Hibernate](https://www.baeldung.com/java-hibernate-multiplebagfetchexception)