On Wed, 10 Nov 2004 16:15:16 +0100, �ukasz Korzybski <[EMAIL PROTECTED]>
wrote:

>Dnia �roda, 10 listopada 2004 10:02, Gerhard Grosse napisa�:
>> On Wed, 10 Nov 2004 01:51:59 +0100, �ukasz Korzybski <[EMAIL PROTECTED]>
>>
>> wrote:
>> >Thanks for reply,
>> >
>> >Dnia �roda, 10 listopada 2004 00:19, Justin Stanczak napisa�:
>> >> Justin Stanczak, Web Manager
>> >> Vincennes University
>
>> >
>> >OK, but then why this code doesn't work as the previous one:
>> >
>> >            Address address = new Address();
>> >            adres.setCity("Rumia1");
>> >            adres.setStreet("Dunikowskiego 10");
>> >
>> >
>> >            OQLQuery query = odmg.newOQLQuery();
>> >            query.create("select osoba from " + Osoba.class.getName() +
>> > "where id=1");
>> >            DList res = (DList) query.execute();
>> >            person = (Person) res.iterator().next();
>> >
>> >            person.setName("Adam");
>> >            person.setAddress(adres);
>> >
>> >            tx.lock(person, tx.WRITE);
>> >            tx.commit();
>> >
>> >I thought that it would store both person and address, but unless I
>> > explicitly write tx.lock(address, tx.WRITE) I get a key violation:
>> >
>> >ERROR: SQLException during the execution of the update (for a
>> > ojbtest.Person): ERROR: insert or update on table "person" violates
>> > foreign key constraint "person_fk_1"
>> >
>> >The only difference is I retrieve person from db rather than create a new
>> > one, I'm lost and haven't got ideas how to use odmg properly.
>>
>> You need to call tx.lock(persion, Transaction.WRITE) _before_
>> modifying the persion object. Otherwise OJB will not recognize that
>> the object has been modified.
>>
>> Gerhard
>>
>
>It doesn't help in this particular case, it seems that I have to do write lock 
>on new object even when I link it as a dependent to some other persistent 
>object.

AFAIK the 'normal' way to manipulate objects in ODMG is: make new
objects persistent by calling Database.makePersistent(newOjbect) and
call tx.lock(existingObject, Transaction.WRITE) before modifying it.
Depending on the implicitLocking setting in OJB.properties, the latter
will automatically write-lock all referenced objects as well.

HTH
Gerhard


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to