-->
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: Bidirectional Many-to-Many Collection Insert Speed
PostPosted: Wed Aug 30, 2006 3:16 pm 
Newbie

Joined: Tue Jun 20, 2006 10:20 pm
Posts: 6
I have a bidirectional many-to-many mapping of sets (foo and bar). Each class has it's own table and a mapping table in between (foo_bar_mapping).

I'm doing some log loading and transforming those logs into the normalized database form, the issue is the speed at which these updates happen...

the code for adding looks like...

in the Foo class... note: getBars() returns a Set of bars.

Code:
public void addBar(Bar aBar) {
   if (!getBars().contains(aBar) {
       getBars().add(aBar);
       aBar.addFoo(this);
   }
}


in the Bar class... note: getFoos() returns a Set of foos.

Code:
public void addFoo(Foo aFoo) {
   if (!getFoos().contains(aFoo) {
       getFoos().add(aFoo);
       aFoo.addBar(this);
   }
}


I can call aFoo.addBar(aBar), save the objects via my DAOs and it works great, but as soon as their gets to be a lot of bars for aFoo it starts to get really slow. The problem is that Hibernate will populate the Set of all bars in aFoo.bars from the database to check for duplicate items. In some casses this can be half a million or more bars for me.

My question is if there is a better techique in hibernate for doing this insert

I could obviously create an SQL statement to insert directly to the foo_bar_mapping table, but it would be the only place in my system that has an SQL statement and that just makes me sad.

I would prefer not to make it a uni-directional mapping as there is places in my code where i use both aFoo.getBars and aBar.getFoos().

I've tried to cache as much as possible, but just the very act of populating that list is killing me on insert times. I haven't found any other way to insert to a mapping table through Hibernate that is referenced only via the foo and bar mapping documents.

Any thoughts, suggestions, techiques on how to do fast inserts for this type of mapping would be most appreciated.


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.