-->
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.  [ 2 posts ] 
Author Message
 Post subject: "Clearing down" Relationships
PostPosted: Tue Oct 19, 2004 12:51 pm 
Beginner
Beginner

Joined: Tue Oct 05, 2004 5:15 am
Posts: 23
Im wondering how best to implement certain delete operations in my application.
Ive got a Topic which has a set of Memberships to it. Each Membership is associated with a Subscriber. To complicate things, a Subscriber has its own association with Membership: It has the concept of a "default" Membership.

One of my use cases is to delete a Topic.
Im trying to thing about the best way to do this... I cant just "fire-and-forget" - Hibernate will arrange for the Memberships to be deleted but what about management of the Subscribers? (E.g, if we delete a default Membership, we need to update the Subscriber).
Triggers aren't an option (MySQL v4).

Should the service code just do this? I.e: Iterate over each membership in the Topic and update the Subscriber if necessary before the delete.
Or is this a good place for an interceptor?
Or is it my own fault for having a screwy model?

Many Thanks,

Dave


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 25, 2004 4:02 am 
Beginner
Beginner

Joined: Tue Oct 05, 2004 5:15 am
Posts: 23
> Each Membership is associated with a Subscriber. To complicate things, a Subscriber has its own association with Membership: It has the concept of a "default" Membership.

to clarify, a Topic has this:

Code:
Set getMemberships()


A Membership has this:

Code:
Subscriber getSubscriber()


And a Subscriber has this:

Code:
Membership getDefaultMembership()


So in my mapping I have a set of Memberships for a Topic.
I can set cascading deletes up so that when a Topic is deleted, the Memberships are also deleted.
But then if I delete a Topic, I might have Subscribers that point to deleted Memberships.

So currently, my service layer looks up the Topic and asks it to "clear()" itself. This, in turn, asks each membership is to clear() itself, which un-links itself from its subscriber (i.e: if subscriber.getDefaultMembership().equals(this), subscriber.setDefaultMembership(null) ).

Does this sound like a reasonable way to do it? It just feels a little "un-clean" to me.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.