Re: Quite a dilemma




"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


.



Relevant Pages

  • Quite a dilemma
    ... than just relationship between ClassA and ClassB so we go with a seperate ... public ClassA getClassAById(int classAId); ... When I call "ClassA getClassAById(int classAId)" method, ...
    (comp.lang.java.programmer)
  • Re: Some thoughts about OO programming
    ... compilers, that try to make code as machine friendly as possible (with ... Alpha designs a class named ClassA. ... Company Beta wants to write a class ClassB. ... libraries are loaded by the dynamic linker of the OS and it ...
    (comp.programming)
  • Re: Can anyone help with proper use of operator CType in VB.net?
    ... public ClassA: inherits Base ... I have an instance of ClassA and ClassB and I'm trying to assign the ... Public Overrides Sub Assign ...
    (microsoft.public.dotnet.languages.vb)
  • Problems loading assembly using System.Reflection.assembly
    ... ClassA is going to be used for multable apps so I ... ClassB inherits ClassA. ... Dim returnObject As Object ... Dim asm As System.Reflection.Assembly ...
    (microsoft.public.dotnet.framework)
  • Problems loading assembly using System.Reflection.assembly
    ... ClassA is going to be used for multable apps so I ... ClassB inherits ClassA. ... Dim returnObject As Object ... Dim asm As System.Reflection.Assembly ...
    (microsoft.public.dotnet.languages.vb)