-->
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: Efficient deleting object, large multiplicity associations
PostPosted: Mon Nov 19, 2007 7:15 am 
Beginner
Beginner

Joined: Mon Feb 19, 2007 4:22 am
Posts: 22
Location: Poland
Hello,

I am looking for solution for this kind of problem:

Let's assume we have an entity 'Item' and it is associated many-to-many with item 'Category'. Something like this:

Code:
public class Item
{
   ...
   Set<Category> categories;
   ...
}


Code:
public class Category
{
   ...
   Set<Item> items;
}



Now, if I delete one Category entity, every associated Item that has been already loaded, must be notified about this deletion (by removing deleted Category entity from it's categories collection). Doing this assures consistency of in-memory model.

One way to do this is to iterate through all Items associated to the Category being deleted, and remove this entity from categories collection, like this:

Code:
public void deleteCategory(Category category)
{
   for(Item items : item)
   {
        item.remove(catgeory);
   }
}


But this leads to initializing whole items collection, possibly causing unnecessary loading of many, many Items objects. For example, if Category is associated to 10 000 Items and my business logic does not need and does not use any of them in a particular Hibernate session, that means loading of 10 000 objects in vain.

I think this 'notification' should only be send to Items that has been already loaded in session (prior to deletion of Category). But I cannot find any solution to get collection of objects loaded to the session. Maybe this is wrong way of thinking? I would like to hear your opinion about this topic. Maybe there are some patterns I haven't found?


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.