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/04/21 22:17:55 UTC

RE: question on auto-retrieve and cacheing behavior for a referen ce d escriptor

OK, I will try that.

Out of curiousity, what is the exact difference between the
refresh attribute and the auto-retrieve attribute?

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


> -----Original Message-----
> From: Ron Gallagher [mailto:rgallagh@bellsouth.net]
> Sent: Monday, April 21, 2003 4:17 PM
> To: ojb-user@db.apache.org
> Subject: Re: question on auto-retrieve and cacheing behavior for a
> reference d escriptor
> 
> 
> Bonnie -- 
> 
> Try setting refresh="true" on the reference-descriptor
> 
> From the DTD:
> 
> "The refresh attribute can be set to true to force OJB to 
> refresh object references on instance loading."
> 
> HTH
> 
> Ron Gallagher
> Atlanta, GA
> rongallagher@bellsouth.net
> 
> 
> > 
> > From: Bonnie MacKellar <BM...@mobius.com>
> > Date: 2003/04/21 Mon PM 04:09:27 EDT
> > To: "OJB Users List (E-mail)" <oj...@db.apache.org>
> > Subject: question on auto-retrieve and cacheing behavior 
> for a reference d
> > 	escriptor
> > 
> > I'm trying to understand  OJB's behavior by looking at the 
> SQL queries
> > that are generated... I do not understand the behavior in 
> this test system.
> > 
> > I have two classes User and Customer. User has a 1:1 relationship to
> > Customer :
> > public class User {
> > 	
> > 	private int userID;
> > 	protected String loginID;
> > 	protected String fname;
> > 	protected String mname;
> > 	protected String lname;
> > 	protected String passwordhash;
> > 	protected int roleID;
> > 	protected Customer customer;
> > 	protected int customerID;
> > 	protected String emailAddress;
> >  ...}
> > 
> > This is set up in repository_user.xml like this :
> >       <reference-descriptor
> >       	name="customer"
> >       	class-ref="database.Customer"
> >       	auto-retrieve="true"
> >       	>
> >       	<foreignkey field-ref="customerID"/>
> >       </reference-descriptor>
> > 
> > Now, I have two records in User :
> > "fred" who has a customerID of 1
> > "susie" who has a customerID of 2
> > 
> > In Customer, I have
> > "acme" with customerID = 1
> > "stuff with customerID = 1
> > 
> > I retrieve the User records by extent :
> > try { 
> >         System.out.println("will retrieve users");        
> >         Query query = new QueryByCriteria(User.class, null);       
> >     
> >         // ask the broker to retrieve the Extent collection
> >         Collection allUsers = broker.getCollectionByQuery(query);
> >         // now iterate over the result to print each product
> >         java.util.Iterator iter = allUsers.iterator();
> >         while (iter.hasNext())
> >         {
> >         	System.out.println("User record : ");
> >         	User user = (User)iter.next();
> >             System.out.println(user.getLoginID());
> >             System.out.println(user.getFname());
> >             System.out.println(user.getLname());
> >             System.out.println(user.getRoleID());
> >             System.out.println(user.getEmailAddress());
> >             System.out.println((user.getCustomer()).getName());
> >             System.out.println("---------------------");
> >         }
> > 
> > As I expect, 1 SQL query to retrieve the User records, and 
> 2 queries to
> > retrieve the Customer records are generated :
> > 50|0|statement|SELECT
> > 
> A0.emailAddress,A0.fname,A0.customerID,A0.passwordhash,A0.mnam
> e,A0.lname,A0.
> > roleID,A0.loginID,A0.userID FROM ActiveBillUser A0
> > 1050954107641|20|0|statement|SELECT
> > 
> postalCode,name,country,customerID,addressLine2,status,address
> Line1,customer
> > Number,dateDeleted,isDeleted,town,customerType FROM Customer WHERE
> > customerID = '1' 
> > 1050954107651|0|0|statement|SELECT
> > 
> postalCode,name,country,customerID,addressLine2,status,address
> Line1,customer
> > Number,dateDeleted,isDeleted,town,customerType FROM Customer WHERE
> > customerID = '2' 
> > 
> > I then insert a User record, with a customerID = 2, which 
> should point to
> > the "stuff" Customer.
> > When I go to retrieve all Users again, using the code 
> above. This time, only
> > the query to select User records is generated. No queries 
> to retrieve
> > Customer records are generated. Yet, the customer name is 
> printed correctly
> > for the first two records. I assume this is because of cacheing?
> > 
> > However, the third record, the one which had just been 
> inserted, throws a
> > Null pointer exception when I try to print its Customer 
> name. Why? It points
> > to the "stuff" customer, which should be in the cache, 
> since the second
> > record, which just printed successfully, also points to it. 
> I clearly do not
> > undertstand something about the intersection of cacheing 
> and retrieval of
> > referenced objects.
> > 
> > I am using 
> > 
> ObjectCacheClass=org.apache.ojb.broker.cache.ObjectCachePerBrokerImpl
> > if it makes a difference.
> > 
> > Any insight, or a pointer to something (besides the 
> tutorial) which would
> > explain
> > this behavior?
> > 
> > Bonnie MacKellar
> > software engineer
> > Mobius Management Systems, Inc.
> > bmackell@mobius.com
> > 
> > 
> > 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
>