Setting FetchMode in native Hibernate

前端 未结 3 1375
长情又很酷
长情又很酷 2021-01-14 00:46

I need to set the fetch mode on my hibernate mappings to be eager in some cases, and lazy in others. I have my default (set through the hbm file) as lazy=\"true\". How do I

3条回答
  •  情书的邮戳
    2021-01-14 01:13

    There is a static initialize(Object) method in the Hibernate main class. You could use that to force loading of your collection:

    MyClass c = (MyClass)session.get(MyClass.class, myClassID);
    Hibernate.initialize(c.getMySetOfMyClass2());
    

    However, a default value of lazy fetching is just that: a default value. You probably want to override the laziness in the mapping for your particular Set.

提交回复
热议问题