Hi All,
I use HQL extensively in our data access layer to build business objects and pass them back to the business services layer.
As we can only eagerly load one collection per HQL query, I have to perform a number of HQL queries to eagerly load the collections that I need.
As the object I'm building up is in the first level Hibernate cache, each HQL query builds up the object tree in the cache. I can then pass this object back from my Data Access Layer and it is fantastic.
The only problem is when an object is indirectly loaded by an earlier HQL query and it is stored in the Hibernate cache as a proxy. Any subsequent HQL query returns a proxy even when I specify a "left join fetch".
The only way I can get around this is to ensure that I anticipate these situations and re-order the HQL to eagerly load the objects in earlier HQL queries.
This solution is not ideal from a maintainability point of view (e.g. having to re-structure hql for every new requirement is time consuming and prone to error).
Apart from doing evicts or immediate loads, do you guys know of any other solutions to this?
Thanks for your help.
Regards,
Gaj
|