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 David Warnock <da...@sundayta.com> on 2003/05/21 17:00:47 UTC

Reference Proxy dispair

Hi,

I have been following all the ideas in the Proxy thread. I still cannot 
get reference proxies to work. I am attaching a really simple example 
with 2 tables Parent and Child. Child has a foreign key reference to 
Parent. I want to avoid executing the sql to load the Parent when I load 
a child unless I refer to the getParent method.

I have tried with and without a ParentInterface. With the Interface I 
get this

     [junit] 
[org.apache.ojb.broker.metadata.fieldaccess.PersistentFieldDefaultImpl] 
ERROR: while set field:
     [junit] object class[ com.sundayta.balloons.model.Child
     [junit] target field: parent
     [junit] java.lang.IllegalArgumentException
     [junit] target field type: class com.sundayta.balloons.model.Parent
     [junit] object value class: $Proxy0
     [junit] object value: com.sundayta.balloons.model.Parent@d6b059]
     [junit]     at 
sun.reflect.UnsafeObjectFieldAccessorImpl.set(UnsafeObjectFieldAccessorImpl.java:63)
     [junit] [org.apache.ojb.broker.accesslayer.RsIterator] ERROR: Error 
setting field:parent in object:com.sundayta.balloons.model.Child
     [junit]     at java.lang.reflect.Field.set(Field.java:519)
     [junit]     at 
org.apache.ojb.broker.metadata.fieldaccess.PersistentFieldDefaultImpl.set(Unknown 
Source)
     [junit]     at 
org.apache.ojb.broker.singlevm.PersistenceBrokerImpl.retrieveReference(Unknown 
Source)
     [junit]     at 
org.apache.ojb.broker.singlevm.PersistenceBrokerImpl.retrieveReferences(Unknown 
Source)
     [junit]     at 
org.apache.ojb.broker.accesslayer.RsIterator.getObjectFromResultSet(Unknown 
Source)
     [junit]     at 
org.apache.ojb.broker.accesslayer.RsIterator.next(Unknown Source)
     [junit]     at 
com.sundayta.balloons.model.ChildTest.testCollection(ChildTest.java:71)

My test does this:

     PersistenceBroker broker = 
PersistenceBrokerFactory.defaultPersistenceBroker();

     Query query = new QueryByCriteria(Child.class, null);
     try {
       Iterator iter = broker.getIteratorByQuery(query);
       while (iter.hasNext()) {
         Child c = (Child)iter.next();
         System.out.println("Id: " + c.getChildId() + " Name: " + 
c.getName() + " parentId: " + c.getParentId() + " parentName: " + 
c.getParent().getName() );
       }
     }
     finally {
       broker.close();
     }

My repository looks like this:

    <class-descriptor
    	  class="com.sundayta.balloons.model.Parent"
    	  table="Parent"
    >
       <field-descriptor
          name="parentId"
          column="ParentId"
          jdbc-type="INTEGER"
          primarykey="true"
          autoincrement="true"
          sequence-name="GEN_ParentId"
       />
       <field-descriptor
          name="rowVersion"
          column="RowVersion"
          jdbc-type="INTEGER"
          locking="true"
       />
       <field-descriptor
          name="name"
          column="Name"
          jdbc-type="VARCHAR"
       />
    </class-descriptor>

    <class-descriptor
     class="com.sundayta.balloons.model.ParentInterface" >
           <extent-class class-ref="com.sundayta.balloons.model.Parent" />
   </class-descriptor>

    <class-descriptor
    	  class="com.sundayta.balloons.model.Child"
    	  table="Child"
    >
       <field-descriptor
          name="childId"
          column="ChildId"
          jdbc-type="INTEGER"
          primarykey="true"
          autoincrement="true"
          sequence-name="GEN_ChildId"
       />
       <field-descriptor
          name="rowVersion"
          column="RowVersion"
          jdbc-type="INTEGER"
          locking="true"
       />
       <field-descriptor
          name="name"
          column="Name"
          jdbc-type="VARCHAR"
       />
       <field-descriptor
          name="parentId"
          column="ParentId"
          jdbc-type="INTEGER"
       />
       <reference-descriptor
          name="parent"
          class-ref="com.sundayta.balloons.model.ParentInterface"
          proxy="true"
          auto-retrieve="true"
          auto-update="false"
          auto-delete="false">
       >
          <foreignkey field-ref="parentId"/>
       </reference-descriptor>
<!--
       <reference-descriptor
          name="parent"
          class-ref="com.sundayta.balloons.model.Parent"
          proxy="true"
          auto-retrieve="true"
          auto-update="false"
          auto-delete="false">
       >
          <foreignkey field-ref="parentId"/>
       </reference-descriptor>
-->
    </class-descriptor>

-- 
David Warnock, Sundayta Ltd. http://www.sundayta.com
iDocSys for Document Management. VisibleResults for Fundraising.
Development and Hosting of Web Applications and Sites.