-->
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.  [ 1 post ] 
Author Message
 Post subject: Hibernate very slow when committing children records
PostPosted: Sat Sep 20, 2008 5:06 pm 
Regular
Regular

Joined: Wed May 11, 2005 11:57 pm
Posts: 80
I am using Hibernate 3.0. I have a one-to-many relationship, let's called it Parent and Child.

The problem that I'm having is that commits are horribly slow ( >2 minutes, which is timing out the database connection ). I did some debugging to try to figure out why they are so slow, and here is what I found:

* When a Child record is saved, Hibernate calls getForInsert() on a BackrefGetter, which seems to have something to do with the one-to-many relationship.
* getForInsert() then calls getOwnerId() on the PersistenceContext.
* getOwnerId() tries to figure out which Parent object owns the Child object being saved. From the best that I can tell from looking at the source code, it iterates through *every* object in the session who's type is Parent, and looks at the children relationship to see if that particular Parent object is the one that owns the child being saved.
* I have a lot of objects in my session, and many of my Parent objects in the session have not had their children() collection loaded yet, so this triggers a bunch of SQL queries to the db to see whether they are the owner of the child record being saved. This is what leads to the performance problems.

Why does Hibernate do this, and how can I solve this problem? I cannot easily upgrade to a newer version of Hibernate, as I have applied my own bug fixes to the version 3.0 source code.


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

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.