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 override this setting in code? MyClass has a set defined of type MyClass2 for which I want to set the FetchMode to EAGER.
Currently, I have something like:
Session s = HibernateUtil.getSessionFactory().openSession(); MyClass c = (MyClass)session.get(MyClass.class, myClassID);
You could try something like this: (code off the top of my head)
I believe that FetchMode.JOIN or FetchMode.SELECT should be used instead of FetchMode.EAGER, though.