-->
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.  [ 5 posts ] 
Author Message
 Post subject: Delete entity in large collections
PostPosted: Wed Oct 12, 2005 9:30 am 
Newbie

Joined: Wed Oct 12, 2005 9:11 am
Posts: 3
Hi there,

i've got a performance problem with one of my "ont-to-many" bidirectional relations:
I have a one-to-many relation bewteen a costumer and his items:
Code:
<bag name="items"
     inverse="true"
                  lazy="true"
                  access="field"
           >
           <key column="itemid"/>
          <one-to-many class=""/>
    </bag>


One customer in the db has about 30.000 items. I get an "OutOfMemory-Exception" when i try to invoke the following code
Code:
     customer1.getItems().delete(item1); // takes ages and ends in an OutOfMemeory exception


I changed already from a set/Set to a bag/List in my mapping /Pojo to get better performace when adding a new Item
Code:
     cusotmer1.getItems().add(item1); // is now very fast


Is there any possibility to get this fast performace out of hibernate when deleting an item????? I don't want to fetch all items into memory before deleting them!


Top
 Profile  
 
 Post subject: ...deleting without fetching
PostPosted: Mon Oct 17, 2005 5:42 am 
Newbie

Joined: Wed Oct 12, 2005 9:11 am
Posts: 3
Does anybody know, if this is possible (deleting from list, without fetching the whole list?).....?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 17, 2005 11:28 am 
Expert
Expert

Joined: Fri Aug 19, 2005 2:11 pm
Posts: 628
Location: Cincinnati
try using query.iterate(). I've never used it but the online docs say objects are initialized on demand.

_________________
Chris

If you were at work doing this voluntarily, imagine what you'd want to see to answer a question.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 17, 2005 7:33 pm 
Expert
Expert

Joined: Thu Jan 08, 2004 6:17 pm
Posts: 278
Generally if you have too many children to safely load into memory, I find there to be little reason to even *have* the parent-side association.

In other words: why do you even have an items collection as part of customer, if it's possible for a customer to have so many items that customer.getItems().<anyMethodAtAll>() will probably cause an immediate OutOfMemoryException? In this case, customer.getItems() is kind of a time bomb just waiting to go off.

I would suggest deleting the customer.getItems() collection altogether. If you need to get the items for a particular customer, do it with an HQL query that lets you select the first item to get and the max items to get in one fetch.

This is what we've done all over our system, anyway. When you get into thousands of children, you pretty much have to start using queries to manage them explicitly, rather than giving Hibernate lazy loading a chance to do the wrong thing (i.e. load them all into memory!).

If you were doing it this way, then there would be no customer.getItems() collection to delete from -- you would just do session.delete(item) and be done with it.

query.iterate() wouldn't help in this case, since it has nothing to do with Hibernate's lazy-loading behavior for getItems.

Cheers,
Rob


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 18, 2005 10:38 am 
Newbie

Joined: Wed Oct 12, 2005 9:11 am
Posts: 3
thanks a lot Rob...
after a lot of changes in the business layer and the unit tests i got your approach to work...
I knew about my time bomb, so i was hoping that there was something to avoid this already built in hibernate...
.. but of course, your approach seems also more "clean" to me

Cheers,
Sven


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.