I think it would be better to change your DB model in this case.
Do you have this two db references: Company - Employee, 1:1 and Employee -
Company, N:1 ?
Actually, you need only one of them (Employee - Company, N:1), you can find
Admin from Employees collection quite easily, i beleive.

Good luck.
Denis.

----- Original Message ----- 
From: "Ravinder Rathi" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Tuesday, June 10, 2003 7:51 PM
Subject: [castor-dev] issue using database.create() or transactions


> Hi
>
> I am facing a issue with database.create(). I have two objects which have
a
> one to one relation.
>
> Company
> {
>        protected String name;
>        protected Employee admin;//reference to 2nd object
> }
>
> Employee
> {
>       protected String name;
>       protected Company mycompany;//reference to 1st object
> }
>
> Both tables in the DB have forign key columns set to 'not null'.
>
> When I try inserting  both objects using db.create(), foerign key column
> does not allow nulls  exception is thrown which is obvious but....
>
> Code to insert objects:
> --------------------------------------------------------------------------
--------
> db.begin();
>
> Company company = new Company();
> company.setName("xyz");
>
> Employee admin = new Employee();
> admin.setName("my name");
>
> admin.setCompany(company);
> company.setAdmin(admin);
>
> db.create(company);
> db.create(admin);
>
> db.commit();
> --------------------------------------------------------------------------
-----------------
> In this kind of situation since both objects have a reference to each
other
> which one do you create first. Since both object are created in the same
> transaction, it should not matter.
>
> I have this kind of relations at many places in the object model and need
> help to solve this issue.
>
> thanks
>
> Ravinder
>
> _________________________________________________________________
> MSN 8 with e-mail virus protection service: 2 months FREE*
> http://join.msn.com/?page=features/virus
>
> ----------------------------------------------------------- 
> If you wish to unsubscribe from this mailing, send mail to
> [EMAIL PROTECTED] with a subject of:
>         unsubscribe castor-dev

----------------------------------------------------------- 
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
        unsubscribe castor-dev

Reply via email to