You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-user@db.apache.org by Frank Rub <f....@frank-rub.de> on 2003/07/25 14:22:08 UTC

Problem using dynamic proxy for lazy loading

Hi all,

I have a Proxy loading problem:

I have two classes "classA" and "classB" 
which do have a 1:n relation

my repository
   <class-descriptor class="com.jmedia.map.entryForm.InterfaceC">
      <extent-class class-ref="com.jmedia.map.entryForm.ClassA" />
      <extent-class class-ref="com.jmedia.map.entryForm.ClassB" />
   </class-descriptor>

   <class-descriptor
   	  class="classA"
   	  table="A_Table"
   >
   ...
   ...
      <collection-descriptor
         name="ClassBCollection"
         element-class-ref="classB"
         auto-retreive="true"
         auto-update="true"
         auto-delete="true"
         orderby="id"
         sort="DESC"
      >
         <inverse-foreignkey field-ref="classAId"/>
      </collection-descriptor>
         
   </classDescriptior>


   <class-descriptor
   	  class="classB"
          proxy="dynamic"
   	  table="B_Table"
   >
      <field-descriptor
         name="classAId"
         column="classAId"
         jdbc-type="INTEGER"
      /> 
      ...
      ...
   </classDescriptior>
	

my java code :-)   

interface interfaceC
{
get **
set **
}

class classA extends interfaceC
{
get **
set **
Collection getClassBCollection();
}

class classB extends interfaceC
{
get **
set **
}

because "class B" is about 30.000 times in "classA" collection
for me it's important to use "lazy loading" because
I only need about 100-500 items from "class B" at one time.

and it works fine
Collection myColl = classA.getClassBCollection();

But if I try to get one Element, and try to cast it to "classB"
classB myclassB = (classB)myColl.next();
it throws a class cast exception
only if I cast to the Interface (InterfaceC) everthing works fine

so the "proxy loader" loads only the interface
with its values and not the whole classB

is it possible to load dynamically all required classB elements
and not only the interfaces ?


thank you in advance.
Frank






---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org


Re: Problem using dynamic proxy for lazy loading

Posted by Armin Waibel <ar...@code-au-lait.de>.
Hi Frank,

> so the "proxy loader" loads only the interface
> with its values and not the whole classB
> 
> is it possible to load dynamically all required classB elements
> and not only the interfaces ?

think you have to write an Interface for B class
too - e.g. interface BC extends C.
'proxy classes' base on declared interfaces, in your
case only on Interface C. 

regards,
Armin


----- Original Message ----- 
From: "Frank Rub" <f....@frank-rub.de>
To: <oj...@db.apache.org>
Sent: Friday, July 25, 2003 2:22 PM
Subject: Problem using dynamic proxy for lazy loading


> Hi all,
> 
> I have a Proxy loading problem:
> 
> I have two classes "classA" and "classB" 
> which do have a 1:n relation
> 
> my repository
>    <class-descriptor class="com.jmedia.map.entryForm.InterfaceC">
>       <extent-class class-ref="com.jmedia.map.entryForm.ClassA" />
>       <extent-class class-ref="com.jmedia.map.entryForm.ClassB" />
>    </class-descriptor>
> 
>    <class-descriptor
>      class="classA"
>      table="A_Table"
>    >
>    ...
>    ...
>       <collection-descriptor
>          name="ClassBCollection"
>          element-class-ref="classB"
>          auto-retreive="true"
>          auto-update="true"
>          auto-delete="true"
>          orderby="id"
>          sort="DESC"
>       >
>          <inverse-foreignkey field-ref="classAId"/>
>       </collection-descriptor>
>          
>    </classDescriptior>
> 
> 
>    <class-descriptor
>      class="classB"
>           proxy="dynamic"
>      table="B_Table"
>    >
>       <field-descriptor
>          name="classAId"
>          column="classAId"
>          jdbc-type="INTEGER"
>       /> 
>       ...
>       ...
>    </classDescriptior>
> 
> 
> my java code :-)   
> 
> interface interfaceC
> {
> get **
> set **
> }
> 
> class classA extends interfaceC
> {
> get **
> set **
> Collection getClassBCollection();
> }
> 
> class classB extends interfaceC
> {
> get **
> set **
> }
> 
> because "class B" is about 30.000 times in "classA" collection
> for me it's important to use "lazy loading" because
> I only need about 100-500 items from "class B" at one time.
> 
> and it works fine
> Collection myColl = classA.getClassBCollection();
> 
> But if I try to get one Element, and try to cast it to "classB"
> classB myclassB = (classB)myColl.next();
> it throws a class cast exception
> only if I cast to the Interface (InterfaceC) everthing works fine
> 
> so the "proxy loader" loads only the interface
> with its values and not the whole classB
> 
> is it possible to load dynamically all required classB elements
> and not only the interfaces ?
> 
> 
> thank you in advance.
> Frank
> 
> 
> 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
> 
> 
> 



---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org