Hi,
I'm trying to get some example code going for this because my code is a bit too much to post up here (14 or so classes). Anyways, I'm loading up (loadAll through Criteria) one abstract type that is an inheritance hierarchy. It has 3 subclasses and each subclass has either a OneToMany or ManyToMany, one of them has both. I have all association relationships set to EAGER and JOIN as well as nullable = false and updatable = false.
My SQL statement appears to come out correctly. It outer joins all of the subclasses as well as all of the associations from all subclasses (including all subclasses of any associations that have inheritance hierarchies. From what I can tell this select loads up all the rows I could possibly need to resolve every association of every row produced by the select. That is, there are no rows which have associations that aren't in one of the rows, or are not one of the rows themselves (I just realized one of the subclass associations links back to the abstract type that I'm loadAll()'ing).
So after all this is loaded in a result set and all my objects are hydrated... the TwoPhaseLoad goes on to its second step and starts doing a select for every single row to populate objects that should have been in the initial ResultSet already! I've poked around my definitions and the strangest thing I have is the fact that my Abstract base class is an association (@ManyToMany) inside one of its' subclasses. Does this sound dangerous?
Past that I traced a lot of the Hibernate code and did find an issue that I think may explain why this is happening. This seems to occur starting at line 701 of the Abstract Loader.class (actually a CriteriaLoader but it doesn't override this code). Past this point we begin to populate the hydrated objects. But for some reason instead of resolving references to entities the hydration process keeps even Eager and JOIN associations as identifiers only. There is an explicit comment stating this in ManyToOneType.class:103.
Once the objects are hydrated (with nothing but identifiers for associations) the resultSet is put aside and new queries are used to complete the loading of all of the collections. This results in lots of selects instead of just the initial resultSet. Any ideas? Am I looking at this code only because my settings are wrong and I should be on another code path? I didn't see one... ideas?
I'll try to get example code running...
|