-->
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.  [ 3 posts ] 
Author Message
 Post subject: Quickly deleting all associations
PostPosted: Tue Jun 15, 2004 2:15 pm 
Newbie

Joined: Fri May 14, 2004 5:38 pm
Posts: 12
Hi all...

I have a strange business case I was hoping to get some advice on.

I have modeled a many-to-many (with the association being a composite object.. A -> AB -> B), and we have one use case where we need to wipe out all the associations.

These tables can be quite large... so I want to avoid having to instantiate potentially thousands of 'A' objects, then loop through and clear their assocaitions to 'B'.

We are currently accomplishing this by executing a raw SQL statement to delete the 'AB' table. This works fine, but it's such a shame to have to sully our SQL-free code with this.

Anyone have any suggestions on a better way to do it?

thanks,

joe


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 15, 2004 2:32 pm 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
for the performance issue, i think doing this use case in pure jdbc is not so bad.
Isolate it in a DAO layer, if possible:
* make this delete work, the first data access of the httpRequest
* get the jdbc connection from hibernate session
* don't forget the transaction
* also call session.clear() after it to ensure the session don't hold wrong data
* then continue your job

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 26, 2005 6:56 am 
Newbie

Joined: Wed Jan 26, 2005 6:38 am
Posts: 1
Location: New Zealand
I have a very similar business case with a slightly different problem.

To illustrate, I have to two objects:

1/ User
2/ Group

The association is as follows:

User -> GroupMembership <- Group

Note: There is not GroupMembership object, this is just the name of the association.

Specifically, a user has a set of Group objects that compose the group memberships for that user. A group has a set of User objects that are members of that group. This is modeled as a bi-directional many-to-many.

If I have a group with a very large membership, then deletion performance can be significantly degraded. This is due to the requirement that I manually dereference the group being deleted from set of group memberships for each user.

I have found that if I do not do this, if a user that belongs to the group being deleted is loaded in the same session and has her group membership set initialised, then exceptions are thrown when the session flushes during the delete operation.

The exception indicates that an attempt was made to save an object during cascade that has already been deleted.

My major issue with this is that there is no easy way to determine which (if any) users have been loaded in the current session and hence must have their memory state updated. I do not wish to iterate the set of members for the group being deleted as it could be enormous and would result in a large amount of data being retrieved unnecessarily from the database.

I understand that this is something that cannot be overcome in hibernate, however I am hoping that there are strategies that might help me to deal with this issue.

Hopefully there is a design pattern that can be of use here. I am unwilling to use hand coded SQL here as I have similar issues in other parts of my data model.


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