Hi,


Jair da Silva Ferreira J�nior wrote:
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();

OK; I see what you mean now, and I think your best bet here is to reload the Order from the database using refresh="true" on the Customer.


    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)?

Unfortunately the auto*-attributes do not affect removeFromCache-calls at all (as far as I have seen, I'm greatful for hints how to achieve this automagically! auto-invalidate="true" in OJB 2.0? ;). What I meant with "re-loading the whole Order" was removing both Order and Customer from cache and loading Order (with refresh="true" loading Customer, which would update the reference-descriptor).


When you tweak your auto*-attributes, think of the cache as non-existant to get it right for your needs. (Or you could just use NoCacheImpl in OJB.properties for testing.) Then when you are done, implement cache-removal for as small och big a structure that you would like re-loaded from the database.

    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?

If you use a cache, it will "interfer" in all instance-loading and reference- and collection-descriptor updating caused by the refresh attribute. Example with meta code:


O-[reference descriptor with auto-retrieve and refresh]->C

load(O) (loads O and C from database)
removeFromCache(O)
load(O) (loads O from database and sets ref to C from cache)
load(O) (loads O and C from cache)
myRemoveFromCache(O) => removeFromCache(C);removeFromCache(O)
load(O) (loads O and C from database)

Thank you very much for your help.

NP; trying to learn myself. :-)


Cheers,
 Martin

--
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]



Reply via email to