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 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);
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.
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.
-- 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]