I have a method (let's call it FOO) that I use a couple of times. The result is an entity (let's call it MyEntity) that contains a lot of EAGER columns. In one scenario, I want this to fetch in a LAZY way.
The problem is that I can't change the entity's Fetch type to LAZY, because most of the times, the EAGER helps, and I can't use entityGraph inside FOO because I want it to be lazy in one scenario. Is there any option to define in advance for a specific session that all the transactions that use MyEntity will be Lazy? (with EntityGraph)
This is the code of the fetching -
Criteria criteria = session.createCriteria(MyEntity.class) .add(Restrictions.eq("rowType.code", (long) rowType)); return criteria.list();
even if I had a way to know that I'm in a specific scenario - how can I add the EntityGraph to the session?