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
>> 812-888-5813
>>
>>
>> "All that is necessary for the triumph of evil is that good men do
>> nothing." Edmund Burke
>>
>
>
>>>1. in Basic O/R mapping I've read that in ODMG default auto-update is set
>>>to
>>>false which is link. I read that in this case ODMG will not insert nor
>>>update
>>>my collection objects if i do write lock on master object. But it does both!
>>>
>>> Transaction tx = odmg.newTransaction();
>>> tx.begin();
>>>
>>> person = new Person("Michal", "Korzybski", new Integer(22));
>>> Address a = new Address();
>>> a.setCity("Rumia");
>>> a.setStreet("Dunikowskiego 2");
>>> person.addAddress(a);
>>>
>>> tx.lock(osoba, tx.WRITE);
>>> tx.commit();
>>>
>>>After this code I've person and address stored in DB. I'm confused.
>>>
>>>
>>Yes, it does by default. I don't think the docs are perfect.
>
>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
>>
>> >3. I can't commit object with null FK and no idea why, probably i'm doing
>> >something wrong.
>>
>> I'm not sure here. You should be able to, or maybe I'm not understanding
>> what you're doing.
>
>The problem was that I had integer as PK/FK rather than Integer so OJB was
>trying to save null as 0 and it caused key violation, my mistake but it took
>me almost a day.
>
>regadrs, naos
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]