-->
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.  [ 3 posts ] 
Author Message
 Post subject: many-to-one query optimization... any further documentation?
PostPosted: Sat Apr 10, 2004 12:51 am 
Newbie

Joined: Sat Apr 10, 2004 12:14 am
Posts: 7
I've read numerous posts and the documentation related to improving performance (chapter 11) but I am still concerned over the number of queries required to load an object with several many-to-one relationships (the one-to-many relationships are set to lazy load and thus not contributing to the problem).

I am using the object references returned by my persistence classes to populate web pages. I need access to some of the "first level" properties of the related many-to-one objects in the web interface. If I understand proxies correctly, this would preclude me from defining proxies for those classes. Unfortunately, this strategy results in 5 or 6 queries being issued to retrieve a single top-level object. The problem is exacerbated by the fact that each of the dependent objects have several many-to-one relationships themselves. The queries are massive and presumably pulling back way more data than I need. Each of the queries for the many-to-one relationships appear to be using outer joins although I've tried playing with various outer-join settings with no reduction in the number of queries.

Can anyone point me to additional documentation on this matter? The docs are helpful, but focus more on the implication of using proxies for polymorphic classes than on addressing the more common scenarios as described above. Or perhaps I could be overreacting? Should scalability concerns be focused on unnecessary initialization of collections rather than the sheer number of queries due to many-to-one relationships?

Using Hibernate 2.1.2.

Thanks in advance. Dan.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Apr 10, 2004 1:59 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
No, it does not preclude the use of proxies.

You need to either:

(1) use open-session-in-view pattern OR
(2) make sure that associations are prefetched before passing control to the view, using explicit initialization (eg. Hibernate.initialize(), or a query with a FETCH JOIN)


Top
 Profile  
 
 Post subject:
PostPosted: Sat Apr 10, 2004 9:09 am 
Newbie

Joined: Sat Apr 10, 2004 12:14 am
Posts: 7
Thank you for your quick reply. I am familiar with the second option (pre-fetching or initializing within the session). This is what I do for lazy loaded one-to-many associations. I never thought of it for many-to-one associations. I will refactor to implement proxies and initialize only those many-to-one relationships necessary for the view. As for the first option (open session in view pattern), I'll have to look the specifics -- hibernate docs? I am using the Springframework with IoC transaction/session management in the resource tier. The framework provides some really nice simplifying abstractions and I'd prefer to stay with the existing patterns (see PetClinic and JPetStore examples in Spring distribution). Nonetheless, I am always interested in learning new ways of doing things. Thanks.

BTW, looking forward to the book and seeing you at the Philadelphia Java user's group in May!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.