Hi, ----- Original Message ----- From: "Martin Kalén" <[EMAIL PROTECTED]> To: "OJB Users List" <[EMAIL PROTECTED]> Sent: Friday, December 05, 2003 7:14 AM Subject: Re: hot to reload cached object?
> Hi! > > Yes; removeFromCache will remove the weak reference to the object and > make it eligble for garbage collection. > > Jair da Silva Ferreira Júnior wrote: > > > transaction.begin(); > > Customer c=new Customer(); > > c.setName("customer"); > > transaction.lock(c,transaction.WRITE); //persist the new customer > > transaction.commit(); > > > > //after some time someone changes Customer's name to "new customer" > > directly in the database > > transaction.begin(); > > Customer c=loadCustomer(); // loads the customer persisted before > > from cache > > Order o=new Order(); > > o.setCustomer(c); > > cache.reloadObject(c); //reload object data from database > > boolean referenceOk=(c==o.getCustomer()); // I wanted referenceOk to > > be true > > To me, it looks like you could just flip the order of setting the > Customer reference in Order and do: > > Customer c=loadCustomer(); // loads the customer persisted before > cache.reloadObject(c); // reload object data from database > Order o=new Order(); > o.setCustomer(c); I know that fliping the order of setting the Customer reference in Order would solve the problem. But that is not my objective. I'm sorry I could not explain you correctly what I wanted. This code better captures my intention: transaction.begin(); Customer c=new Customer(); c.setName("customer"); Order o=new Order(); o.setCustomer(c); transaction.lock(c,transaction.WRITE); //persist the new customer transaction.lock(o,transaction.WRITE); //persist the new order transaction.commit(); //after some time someone changes Customer's name to "new customer" directly in the database transaction.begin(); Customer c=loadCustomer(); // runs a query to load the Customer persisted before from cache Order o=loadOrder(); // runs a query to load the Order persisted before from cache cache.reloadObject(c); //reload object data from database mutating the input parameter "c" boolean referenceOk=(c==o.getCustomer()); // I wanted referenceOk to be true boolean dataReloaded="new customer".equals(c.getName()); //I wanted dataReloaded to be true transaction.commit(); > > I cant't tell from your example wether cache.reloadObject(c) returns a > new pointer or mutates the input parameter. If it is not mutating you > could pick up the newly loaded object reference as return value and do: > > Customer c=loadCustomer(); > c = cache.reloadObject(c); > Order o=new Order(); > o.setCustomer(c); cache.reloadObject(c) should mutate the input parameter instead of returning a new pointer > Also, have a look at the "auto-retrieve" and "refresh" attributes in the > repository file to tweak how a Customer-reference from an Order should > be updated when re-loading the whole Order. What do you mean by "re-loading the whole Order"? Do you mean re-loading it from cache or from the database? If auto-retrieve="true" and refresh="true", when the Customer is removed from cache (using broker.removeFromCache(c)), would the Order reference to the customer be automaticaly updated too? If true, when would this automaticaly update happen? After a query to Customer (reloading it from the database) or after a query to Order (getting it from the cache)? > In one of our applications we have wrapped load-operations to be: > 1. remove from cache > 2. get object by query > > Any reference- or collection-descriptors in step 2 have @refresh="true" > in the repository and will be reloaded as well (provided that you follow > reference-descriptors and remove them from cache too in step 1). Or you > could just follow Armin Waibel's instructions about clearing the whole > cache if you would like _all_ objects to be reloaded. I've read the documentation of the refresh atribute in the <class-descriptor> tag but I'm still confused. If refresh="true" when an object is loaded from cache, are its data and references also reloaded from the database? If this is true, what is the point of retrieving it from cache? Thank you very much for your help. Sincerely, Jair Jr > -- > Martin Kalén > Curalia AB Web: http://www.curalia.se > Orrspelsvägen 2B Mail: [EMAIL PROTECTED] > SE-182 79 Stocksund Tel: +46-8-410 064 40 > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]