Richard,
please see inline for comments/questions ...
Werner
--Original Message Text---
From: Richard Grill
Date: Mon, 7 Jul 2003 13:16:59 +0200
Hello everybody,
I've following - probably very trivial - problem:
I've 3 tables and 3 classes:
* table TPerson (has foreign key to table TPersonType Not Null) and class CPerson (has
attribute objPersonType of
class CPersonType - pointer to child object attribute),
* table TPersonType (has foreign key to table TPersonTypeCategory Not Null) and class
CPersonType (has attribute
objPersonTypeCategory of class CPersonTypeCategory - pointer child object attribute),
* table TPersonTypeCategory and class CPersonTypeCategory.
I set access="shared" for all classes in the mapp.xml.
I'm able to load required objPersonType and perform creating new objPerson via new
CPersonType() and set
previously loaded child object attribute then I called
db.create(objPerson). Everything is OK, Foreign key to TPersonType is also set OK.
During another scenario I need to refresh objPerson in Castor Cache form DB and want
to avoid other JDBC apps
modify objPerson - I load objPerson as db.locked ...
<werner>
Why are you trying to use db.locked anyway ? In what environment are you operating ? I
mean, if you are afraid that
in a multi-threaded environment multiple threads might access and want to modify your
CPerson instances, don't !
Castor by default uses a positive locking mechanism, and prevents such a scenario from
happening. In other words,
if
you've got two threads trying to e.g. modify the category for one and the same CPerson
instance, only one will
succeed. The other thread will be delivered a notification (an exception) indicating
that the underlying object has
changed and hence cannot be persisted. It would be very simple to come up with a bit
of code and design to e.g.
reread the object in question and present the user (in case you have users) with the
same update form again.
Using db.locked is a very expensive solution in terms of latencies introduced to your
system (especially when the
same could be achieved in a different way), and migth prevent you from achieving an
adequate performance.
</werner>
=> master object objPerson is locked in DB and all DB records corresponding to child
objects (objPersonType and
onjPersonTypeCategory) were also locked (until db.commit).
My problem is that I don't want to lock child objects in this scenario, I want to lock
& update just objPerson.
When I changed access="read-only" for child classes (CPersonType and
CPersonTypeCategory) - no child object
lock was present (it's OK), but I wasn't able create new obj Person - there was DB
error thrown (ORA-02291)- Parent
key has not found - that means value for foreign key ID_FK_PERSON_TYPE is not
correctly provided by CASTOR.
werner -> Did Castor throw any exception in this case, and if so, can you please
provide teh complete stack trace ?
So, how to avoid locking & updating of whole hierarchy of child objects when only
master object locking is required -
but having possibility to correctly update child object attribute pointer - that is
objPerson.setObjPersonType
(objPersonType1). Note that modifying of objPersonType1 itself is never required
during runtime - it's some kind of
pre-
configured data.
werner -> If that's the case, how are you defining the mapping for CPersonType and
CPersonCategory. Are they
defined as read-only (as part of the <class> element) and are you using a cache. If
CPersonType and
CPersonCategory are static in the sense that they will never be modified during their
life-time, using a cache will have
quite an impact on performance.
Could you please be so kind and help me ?
Thanks a lot for your help
Richard
here's the fragment from mapp.xml - it shows how is child object attribute configured:
<class auto-complete="false" name="package1.CPerson" access="shared"
key-generator="HIGH-LOW" identity="ID">
<description>Default mapping for class package1.CPerson</description>
<cache-type capacity="1000" type="count-limited"/>
<map-to table="TPerson" xml="CPerson"/>
<field required="false" transient="false" direct="false"
name="objPersonType" type="package1.CPersonType" lazy="false">
<sql name="ID_FK_PERSON_TYPE" dirty="check" read-only="false"/>
<bind-xml node="element" name="objPersonType"/>
</field>
...
-----------------------------------------------------------
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
unsubscribe castor-dev