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: Bidirectional mappings + hierachy = bad performance?
PostPosted: Fri Jul 15, 2005 9:29 am 
Newbie

Joined: Fri Jul 15, 2005 9:00 am
Posts: 1
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version: 2.1.8

Hi

I’ve got a ”funny” problem. To simplify things I’ve used the objects Dog and Cat in the following example.

A Dog has a reference to a parent Dog, and a set of Cats.
A Cat has a set of Dog’s.

When I load my application, all Cat’s and Dog’s are loaded from the DB and stored in two lists (List dogs and List cats).
On each Dog object, I have a list of children generated by a method:
Public List getChildrenByParentPk(long pk).

Here is the mapping:

---------------------------------------------------------
Dog

<many-to-one name=”parent” class=”Dog” column=”dog_fk”/>

<set name=”cats” table=”cat_dog_rel”>
<key column=”dog_fk”/>
<many-to-many class=”Cats” column=”cat_fk”/>
</set>

Cat

<set name=”dogs” table=”cat_dog_rel”>
<key column=”cat_fk”/>
<many-to-many class=”Dogs” column=”dog_fk”/>
</set>
---------------------------------------------------------


The problem:
It takes a LONG time to load the children – approx. 40 seconds pr. Dog (which is pretty annoying if I have 1000 Dog’s). However, if I remove the “cats” set from the Dog mapping, it takes under 1 second.

I’ve tried to change some settings in hibernate like: cache-settings and hibernate.max_fetch_depth, but with the same result.

Are there anyone else out there who’ve had similar problems with this combination of hierarchy and bidirectional sets?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 15, 2005 2:36 pm 
Senior
Senior

Joined: Wed Jul 13, 2005 4:31 pm
Posts: 142
Location: Seattle, WA
multple options...
a. use lazy="true"
b. check the indexes. We had the problem that when there wasn't proper indexes defined, the queries were taking long time
c. use batch-size="100" say.


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.