-->
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: where does logic for maintaing class relationships go?
PostPosted: Sat Nov 27, 2004 7:06 pm 
Regular
Regular

Joined: Mon Sep 20, 2004 8:42 am
Posts: 58
Location: Boston, US
I have a class A that has a many-to-1 relationship with B and 1-to-many relationship with class C.

Assume tables with class names exist. C has a foreign key to A. and A as a foreign key to B.

Now by business needs are that when an instance of A is deleted, the FK column values referencing the A instance in table C set to null. And the entry in the A table is deleted.

Since we have to maintain the object relationships manually, I do the following (assume 'a' is associated with two 'c' instances)

Code:
a.removeC(c1);
a.removeC(c2);
c1.setA(null);
c2.setA(null);

a.setB(null);
b.removeA(a);

aDAO.remove(a);



And this works fine. Now the question I have is should I move this logical sequence of maintaining the object relationships under the hoods of the DAO remove() method? Or should this sequence of code be in the service method that "deletes" an instance of A? What if multiple services need to carry out the same "delete"..

Most of the examples I've seen have separate methods on each entity to maintain the relationship with another entity and the DAO simply calls delete. However in the case I described, for a remove operation, the logical unit of relationship is across three classes and not two.

Thanks,
Sanjiv

Code:
class A
{
    private B b;
    private Set cees;
}


class B
{
     private A a;
}

class C
{
   private A a;
}



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.