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 蔡博至 <Do...@dsc.com.tw> on 2003/06/25 11:10:22 UTC

Re: Problem of dynamic proxy?

MessageHi! Jim

I have solve this problem.There is not any way to repleace Dynamic Proxy.
But I can tell you how to use "Proxy" via OJB correctly.

1. The class A there is a referance to class B , and the class-descriptor of A must be declared a reference-descriptor for B.
code
------------------------------------------------------------------
public class A{
     :
     :
 private String bOID;
 public String getBOID(){...}
 public void setBOID(String pNewValue){...} 
 
 private InterfaceB objectB;
 public InterfaceB getObjectB(){...}
 public void setObjectB(InterfaceB pNewValue){...} 
}

public class B implement InterfaceB{
 public int get**(){...}
         :
         :
}
public interface InterfaceB {
 public int get**();
  :
  :
}

repository-user content
--------------------------------------------------------------------------
 <class-descriptor class="InterfaceB">
     <extent-class class-ref="B" />
 </class-descriptor>
 <class-descriptor class="A" table="A">
    :
    :
    :
  <field-descriptor name="bOID" column="bOID" jdbc-type="CHAR"/>
  <reference-descriptor name="objectB" class-ref="InterfaceB">
   <foreignkey field-ref="bOID"/>
  </reference-descriptor>
 </class-descriptor>

 <class-descriptor class="B" table="B" proxy="dynamic">
   :
   :
   :
 </class-descriptor>


2. The class A there is a collection property that elements of collection are B, and you want to lazy load elements of collection when OJB load A.
code
------------------------------------------------------------------
public class A{
 private String OID;
 public String getOID(){...}
 public void setOID(String pNewValue){...}
     :
     :
 private Collection manyB;
 public Collection getManyB(){...}
 public void setManyB(Collection pNewValue){...}

}

public class B{
 private String aOID;
 public String getAOID(){...}
 public void setAOID(String pNewValue){...}
         
}


repository-user content
--------------------------------------------------------------------------

 <class-descriptor class="A" table="A">
  <field-descriptor name="OID" column="OID" jdbc-type="CHAR" primarykey="true" autoincrement="true" nullable="false"/>
    :
    :
    :
  <collection-descriptor name="manyB" element-class-ref="B" proxy="true">
   <inverse-foreignkey field-ref="aOID"/>
  </collection-descriptor>
 </class-descriptor>

 <class-descriptor class="B" table="B">
   :
   :
  <field-descriptor name="aOID" column="aOID" jdbc-type="CHAR"/>
   :
   :
   :
 </class-descriptor>

In case 1. You must add a interface class for B and  in respository file declare class-descriptor for it.  Then change the setting of class A and B in respository file.
         Set the B's proxy attribute is important.

In case2. If you want to set collection propertise in your programs lazy load (like us), just declare the proxy attribute of 
          collction-descroptor true.

If you still have problem about lazy load(proxy), mail to me.
  ----- Original Message ----- 
  From: Jim Shingler 
  To: Dogie@dsc.com.tw 
  Sent: Tuesday, June 24, 2003 9:34 PM
  Subject: RE: Problem of dynamic proxy?


  I was reading the Archives.

  I have the exact same issue.

  Did you ever get it figured out. is there a way to solve this other than abandoning Dynamic Proxy?

  You response is much appreciated.

  Jim Shingler