Hibernate throws MultipleBagFetchException - cannot simultaneously fetch multiple bags

前端 未结 15 1965
广开言路
广开言路 2020-11-22 12:49

Hibernate throws this exception during SessionFactory creation:

org.hibernate.loader.MultipleBagFetchException: cannot simultaneously fetch multiple b

15条回答
  •  自闭症患者
    2020-11-22 13:05

    I think a newer version of hibernate (supporting JPA 2.0) should handle this. But otherwise you can work it around by annotating the collection fields with:

    @LazyCollection(LazyCollectionOption.FALSE)
    

    Remember to remove the fetchType attribute from the @*ToMany annotation.

    But note that in most cases a Set is more appropriate than List, so unless you really need a List - go for Set

    But remind that with using sets you won't eliminate the underlaying Cartesian Product as described by Vlad Mihalcea in his answer!

提交回复
热议问题