Hibernate throws MultipleBagFetchException - cannot simultaneously fetch multiple bags

前端 未结 15 2047
广开言路
广开言路 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:13

    For me, the problem was having nested EAGER fetches.

    One solution is to set the nested fields to LAZY and use Hibernate.initialize() to load the nested field(s):

    x = session.get(ClassName.class, id);
    Hibernate.initialize(x.getNestedField());
    

提交回复
热议问题