Hello,


I would like to share my experience on using castor in a webapp whereby using long transactions is inevitably a necessity. The main problems occur using the update() function call. Suppose you have different warehouses storing products and that each warehouse is located in a country.

Shipment (many) <--> (one) warehouse (many) <--> (one) Country

When i display the results of a shipments query in my webpage in want to display the warehouse and the country next to it. When updating for instance the dimensions of a certain shipment I need to :

db.begin();
... OQL ...querying shipments
db.commit();

... user picks a shipment + updates

shipment.setWeight(100);
shipment.setWidth(200);

... and we try to update;

db.begin();
db.update(shipment.getWarehouse().getCountry());
db.update(shipment.getWarehouse());
db.update(shipment);
db.commit();

Using autoStore to prevent all this update code doesnt work because this will always trigger inserts into the database for dependent objects. Right ?

Then the problem gets worse because another user can at same time do more OQL queries relating to the same warehouse and/or country. What happens is that the object shipment.getWarehouse() or shipment.getWarehouse().getCountry() or no longer the last copies of the cache and the jdoTimeStamp has changed. So result of the update : ObjectModifiedException.Although the country table is the most static one around.
This you can workaround by knowing the last loaded copy and fiddling with the timestamp but when two different shipments are active in the same transaction - but loaded in two different transactions - for warehouses in the same coutnry, you end up with a DuplicateEntity exception.


IMO, the FEEM section at www.brainopolis.com/castorwiki/Wiki.jsp?page=FEEM gives solutions

I think not using relationships is not an option either. Using the relationships that have dependent/related 
objects loaded automatically is great to work with it in Struts using the nested tag <bean:write 
name="myShipment" property="warehouse.country"/>; A real time saver?.
But for updates with objects that have relationships, I'm giving up and I do them via 
plain SQL Datasource using stored procs. And then unfortunately reload whatever 
necesary :-/
I end up with a solution where I use castor for all select(OQL) and creation(so far) 
but not for updates.


Any feedback ?


thx,

koen

----------------------------------------------------------- If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
unsubscribe castor-dev




Reply via email to