Re: Quite a dilemma
- From: "Oliver Wong" <owong@xxxxxxxxxxxxxx>
- Date: Tue, 06 Sep 2005 20:46:55 GMT
"Rizwan" <hussains@xxxxxxxxxxxx> wrote in message
news:zXhTe.8977$vN.357821@xxxxxxxxxxxxxxxxxxxxxxxx
>I have 2 classes "ClassA" (mapped to TableA) and "ClassB" (mapped to
>TableB). There is many-to-many relationship between these classes which is
>represented by "ClassAB" (mapped to TableAB). ClassAB is a little bit more
>than just relationship between ClassA and ClassB so we go with a seperate
>class.
>
> public class ClassA {
> private int classAId;
> private Set classABs = new HashSet(); // of type ClassAB
> ...
> }
> public class ClassB {
> private int classBId;
> private Set classABs = new HashSet(); // of type ClassAB
> ...
> }
> public class ClassAB {
> private int classABId;
> private ClassA classA;
> private ClassB classB;
> ...
> }
>
>
> I have these DAO methods:
>
> public ClassA getClassAById( int classAId );
> public ClassB getClassBById( int classBId );
> public ClassAB getClassABById( int classABId );
> public Set getClassABsByClassA( ClassA classA );
> public Set getClassABsByClassB( ClassB classB );
>
>
> When I call "ClassA getClassAById( int classAId )" method, first I
> retrieve data from TableA, populate it in ClassA object and then I call
> the "Set getClassABsByClassA( ClassA classA )" method. This method
> retreive data from TableAB, populate it in ClassAB objects and put them in
> a Set and then returns the Set. Then the "ClassA getClassAById( int
> classAId )" set that Set in the ClassA object and then returns the ClassA
> object.
>
> Problem is that "Set getClassABsByClassA( ClassA classA )" method also
> tries to resolve all the references in ClassAB. Since ClassAB has 2
> references ClassA and ClassB so it retrieves them as well. So for
> resolving reference to ClassA it calls "ClassA getClassAById( int
> classAId )" method. The result is a loop:
> * "ClassA getClassAById( int classAId )" calls "Set getClassABsByClassA(
> ClassA classA )"
> * "Set getClassABsByClassA( ClassA classA )" calls "ClassA
> getClassAById( int classAId )"
>
> Am I doing something wrong? Or is it how it is supposed to work? Please
> reply.
Your class names and method names are really confusing, and you don't
specify in which class the DAO methods are defined. Try posting a SSCCE
(http://www.physci.org/codes/sscce.jsp) and it might be easier to help you.
- Oliver
.
- Follow-Ups:
- Re: Quite a dilemma
- From: Rizwan
- Re: Quite a dilemma
- References:
- Quite a dilemma
- From: Rizwan
- Quite a dilemma
- Prev by Date: Re: How to crypt and De-crpyt a password with a key?
- Next by Date: Re: Java v/s ImageMagick
- Previous by thread: Quite a dilemma
- Next by thread: Re: Quite a dilemma
- Index(es):
Relevant Pages
|