Re: Circular references issue

"Bruno CROS" <[email protected]>
Newsgroups gmane.comp.jakarta.ojb.user
Message-ID <[email protected]>
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 <[email protected]> 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: [email protected]
> For additional commands, e-mail: [email protected]
>
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.