I suggest to use DataContext.invalidateObjects() to restore the
object state after OptimisticLockingFailure. This will of course
override all uncommitted changes on those objects, but this may be
exactly what you want.
Andrus
On Apr 19, 2007, at 6:29 PM, Ayhan Kondoz wrote:
Hi,
i have a problem with refreshing of cached objects.
I do something like this:
SelectQuery query = new SelectQuery
(de.freenet.cayenne.kontingent.Customer.class, Expression.fromString
("cid = " + cid));
List list = context.performQuery(query);
Customer customer = list.get(0);
List accounts = c.getAccounts();
Account a = accounts.get(0);
a.setAmount(amount);
context.commitChanges();
I am using Optimistic Locking on the Account Object and what I need
to do is to catch the OptimisticLockException which may be thrown
and redo the steps again. So if the data of the Account is changed
within the database while I am using it I want to reload the
customer and all it's related objects and try again.
My problem is that after the OptimisticLockException is thrown the
data within the Account object is not reloaded from the database. I
tried to use
query.setRefreshingObject(true);
but still no changes.
In the logging file I see that cayenne entries like this:
SELECT t0.cid, t0.last_updated, t0.login, t0.next_cycle_date,
t0.rec_change, t0.rec_create, t0.suspended, t0.id, t0.mandant_id
FROM customer t0 WHERE t0.cid = ? [bind: 7]
SELECT t0.activation_date, t0.amount, t0.credit_limit,
t0.expire_date, t0.next_cycle_date, t0.rec_change, t0.rec_create,
t0.account_type_id, t0.customer_id, t0.id, t0.unit_id FROM account
t0 WHERE t0.customer_id = ? [bind: 797380]
But the objects I get still contain the old data and I keep getting
OptimisticLockExceptions. How do I tell cayenne to reload the
customer and all it's related object from the database???
I am using cayenne 1.2.1, with shared caching and JavaGroups.
Thanx
Ayhan Kondoz
Ayhan Kondoz
Software-Entwicklung
----------------------------------------------------------------------
------------
Telefon: +49 (0) 40 513 06 616
Telefax: +49 (0) 40 513 06 998 616
E-Mail: [EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]
ag.de>
Website: http://www.freenet.de <http://www.freenet.de/> ; http://
www.freenet-ag.de <http://www.freenet-ag.de/>
----------------------------------------------------------------------
------------
freenet.de AG
Deelbögenkamp 4c
22297 Hamburg
----------------------------------------------------------------------
------------
Vorsitzender des Aufsichtsrates: Prof. Dr. Helmut Thoma
Vorstand: Eckhard Spoerr (Vors.),
Axel Krieger, Stephan Esch, Eric Berger
Amtsgericht Hamburg HRB 74048