These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Outer Join running with N+1 Selects
PostPosted: Fri Dec 04, 2009 4:33 pm 
Newbie

Joined: Mon Feb 23, 2009 11:16 am
Posts: 17
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...


Top
 Profile  
 
 Post subject: Re: Outer Join running with N+1 Selects
PostPosted: Fri Dec 04, 2009 4:39 pm 
Newbie

Joined: Mon Feb 23, 2009 11:16 am
Posts: 17
I found the code starting at Loader.class:1361 odd. The code checks if the property "isEagerPropertyFetchEnabled(i)" but this call goes to a method (for CriteriaLoader.class) that simply returns false always.

Looking further into the code (TwoPhaseLoad.addUninitializedEntity() and persister.hydrate() (in this case it's a JoinSubclassPersister I believe)) there aren't any checks for eager loading and the code specifically (as mentioned above) does not load up eager joins here.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.