I have a SQL statement that I'm using as a basis for a SQL Query. The base entity mapped returns it no problem. The base entity has 3 bags - which are mapped to other objects using their foreign keys.
The issue I'm having is that I want to return deeper sets of objects based on a runtime parameter, and I can't seem to set any fetch mode parameters for SQL Query.
In essence, I need to at runtime be able to either load all the child records or omit them from my final object.
I've partially solved the problem in a "hackish" way by adding a filter that will pass "1 = 2" to the query loading the bag when the filter is enabled:
Code:
<bag ..>
...
<filter name="no-children" condition="1 = 2"/>
</bag>
Not happy with it, but I wasn't able to find another way. (If there is a better way please let me know; I wasn't able to find a way too set a depth value or anything to zero to not load child elements, or to just tell the SQLQuery object not to load children or specific properties).
The issue is that for this object to be usable after the Hibernate session is closed I need to force eager loading. I don't want to change the "default" to not lazy in the mapping XML if I don't have to; I want to say "for this SQL query load with a fetch mode of EAGER". Or if I have to specifically define which bag properties I want to load "eager".