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?