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 Bonnie MacKellar <BM...@mobius.com> on 2003/05/19 20:56:32 UTC

query generation with proxies

I am having trouble understanding the SQL queries which are generated
when I proxy a class. The generated queries do not make sense to me,
and I was hoping someone could explain.

I have a class User. Its entry in repository_user.xml looks like this :
 <class-descriptor
   	  class="database.User"
   	  proxy="dynamic"
   	  table="ActiveBillUser"
   >
      <field-descriptor
         name="userID"
         column="userID"
         jdbc-type="INTEGER"
         primarykey="true"
         autoincrement="true"
      />
      <field-descriptor
         name="loginID"
         column="loginID"
         jdbc-type="VARCHAR"
      />
      <field-descriptor
         name="fname"
         column="fname"
         jdbc-type="VARCHAR"
      />
      <field-descriptor
         name="mname"
         column="mname"
         jdbc-type="VARCHAR"
      />
      <field-descriptor
         name="lname"
         column="lname"
         jdbc-type="VARCHAR"
      />
      <field-descriptor
         name="passwordhash"
         column="passwordhash"
         jdbc-type="VARCHAR"
      />
      <field-descriptor
         name="roleID"
         column="roleID"
         jdbc-type="INTEGER"
      />
      <field-descriptor
         name="customerID"
         column="customerID"
         jdbc-type="INTEGER"
      />    
      <field-descriptor
         name="emailAddress"
         column="emailAddress"
         jdbc-type="VARCHAR"
      />
      <reference-descriptor
      	name="customer"
      	class-ref="database.Customer"
      	auto-retrieve="true"
      	refresh="false"
      	>
      	<foreignkey field-ref="customerID"/>
      </reference-descriptor>
      <collection-descriptor
      	name="accounts"
      	element-class-ref="database.Account"
      	auto-retrieve="false"
      	auto-update="false"
      	indirection-table="Custodian"
        >
      	<fk-pointing-to-this-class column="userID" />
        <fk-pointing-to-element-class column="accountID" />
      	</collection-descriptor> 
   </class-descriptor>

I am doing the simplest possible thing with it : retrieving all instances.
The code looks like this :
try { 
        System.out.println("will retrieve users");        
        Query query = new QueryByCriteria(User.class, null);       
    
        
        Collection allUsers = broker.getCollectionByQuery(query);
     
        java.util.Iterator iter = allUsers.iterator();
        while (iter.hasNext())
        {
        	
        	System.out.println("User record : ");
        	InterfaceUser user = (InterfaceUser)iter.next();
            System.out.println(user.getLoginID());
         }

When I run this against a table with M records,  M+1 queries are generated.
OK, I guess that
makes sense. The first one retrieves all fields of 
all records from the table in the standard fashion. The rest retrieve the
records, one by one,
by user ID. The code works fine, and all records are printed out. This makes
no sense to
me. Why does the first query retrieve all fields? I would have expected it
to retrieve just
the userID, right? I thought that was how proxies worked. This makes no
sense at all.
It would be more efficient to NOT use a proxy.

Here are the generated queries :
SELECT
A0.emailAddress,A0.fname,A0.customerID,A0.passwordhash,A0.mname,A0.lname,A0.
roleID,A0.loginID,A0.userID FROM ActiveBillUser A0
SELECT
emailAddress,fname,customerID,passwordhash,mname,lname,roleID,loginID,userID
FROM ActiveBillUser WHERE userID = '1' 
SELECT
emailAddress,fname,customerID,passwordhash,mname,lname,roleID,loginID,userID
FROM ActiveBillUser WHERE userID = '2' 

thanks,
Bonnie MacKellar
software engineer
Mobius Management Systems, Inc.
bmackell@mobius.com