[prev in list] [next in list] [prev in thread] [next in thread] 

List:       ojb-user
Subject:    Re: Circular references issue
From:       Armin Waibel <arminw () apache ! org>
Date:       2006-12-07 15:54:11
Message-ID: 45783923.2050005 () apache ! org
[Download RAW message or body]

Hi Gautam,

Bruno is right, you have to do two steps on insert of objects with 
bidirectional references. Say class A and B have a bidirectional 1:1 
reference, then do e.g.

A a = new A();
B b = new B();
a.setB(b); // set one reference
broker.beginTx
broker.store(a,..);
b.setA(a); // set other
broker.store(b,..);
broker.commitTx

regards,
Armin

Bruno CROS wrote:
> Hello,
> 
> I guess you have to do the 2 steps in the same way with PB API. Database
> constraints needs the same sequence of insert/update.
> 
> If using  PB API, i don't think you're dealing with rollback ability, if
> not, write the 2 steps as it were 2 standalone PB processes and it should
> work.
> 
> Else, find out how to flush with PB API (post queries without commit).
> 
> Regards
> 
> 
> 
> On 6 Dec 2006 18:15:07 -0000, Virgo Smart <virgosmart@rediffmail.com> 
> wrote:
>>
>>
>> Hello,
>>
>> Is there a way to do the same using Persistence Broker APIs ?
>>
>> Thanks and Regards,
>> Gautam.
>>
>>
>> On Wed, 06 Dec 2006 Bruno CROS wrote :
>> >The circular references have to be build in 2 steps :
>> >
>> >First, create instances and link one relation.
>> >Flush (write SQL insert and update)
>> >Second, link with the second relation (in back side).
>> >Commit.
>> >
>> >Your example :
>> >
>> >tx.begin();
>> >d = new Drawer();
>> >f = new Finish();
>> >tx.lock(d);
>> >tx.lock(f);
>> >d.setFinish(f);
>> >((ExtTransaction) tx).flush() // post INSERT queries
>> >f.setDrawer(d);
>> >tx.commit();
>> >
>> >If you have to delete one object, you have to break the circular
>> reference
>> >in the same way.
>> >
>> >tx.lock(d);
>> >d.setFinish(null);
>> >ExtTx.flush(); // post UPDATE set FINISHPK=null
>> >Impl.getDatabase().deletePersistent(f);
>> >tx.commit();
>> >
>> >Don't change java class definition (circular references relations), 
>> write
>> >your processes as you should do with JDBC only.
>> >
>> >Bruno.
>> >
>> >On 12/6/06, Armin Waibel <arminw@apache.org> wrote:
>> >>
>> >>Hello,
>> >>
>> >>I have a scenario in which there are two classes which reference each
>> >>other. Eg. class Drawer references Finish and Finish references Drawer.
>> >>When I attempt to persist Drawer instance, an exception is thrown
>> >>suggesting that we cannot add or update a child row: a foreign key
>> >>reference fails.
>> >>
>> >>Is there a way to correct this problem without changing the Java class
>> >>definitions ?
>> >>
>> >>Thanks and Regards,
>> >>Gautam.
>> >>
>> >>
>> >>---------------------------------------------------------------------
>> >>To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
>> >>For additional commands, e-mail: ojb-user-help@db.apache.org
>> >>
>> >>
>>
>>
>>
>>
>>
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic