You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-user@db.apache.org by Saleem Shafi <sa...@gmail.com> on 2004/09/29 00:12:33 UTC

more fun with inheritance over multiple tables

To be perfectly honest, i'm not 100% sure this problem is restricted
to inheritance over multiple tables, but that's the configuration i'm
running into the problem with.

Here's the setup:  i've got a base class (Role) and a subclass
(Faculty).  There's a ROLE table and a FACULTY table and it's mapped
according to the description of option #3 in the guide.  Role defines
a 1-to-1 relationship with Person and there's a column in the ROLE
table that corresponds to the pk of the PERSON table.

In the code, i create a Person object and a Faculty object and set the
reference on Faculty (inherited from Role) to the newly created
Person.  Depending on how i setup my descriptor for Role, i run into 1
of 2 problems.  1) If i set the auto-update flag on the Person
reference descriptor to 'true', i get an SQL exception complaining
about cannot insert duplicate key on Person because when the Role
object (added to the transaction when i locked Faculty, i assume to
handle persisting the necessary information to the ROLE table) tries
to insert into the Person table in accordance with the auto-update
flag, but of course, so does the actual Person object.  Or, 2) if i
set the auto-update flag to false, committing the Role fails because
of the inability to satisfy the foreign key relationship to Person.

In situation #1, i would expect OJB to recognize that it has already
inserted the Person object and does not need to do so again; and, in
situation #2, i would expect the reorder() method in the
ObjectEnvelopeTable to recognize that the Role needs to be committed
after Person.  I realize that OJB doesn't know anything about my
foreign key constraints on the database, but i couldn't find any way
to explicity define the dependency between the two objects.

Does anyone know of any way around this mess other than dropping the
foreign key constraint?


Saleem.

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


Re: more fun with inheritance over multiple tables

Posted by "Ludovic Maitre (POP - Factory Part)" <lm...@factory-part.com>.
Hello,

For one project i have adapted OJB to support multiple table inheritance.
The way i have patched OJB perhaps do not suite your needs but you can 
read the patchs reports on the following page:
http://dev.factory-part.com/oss/ojb/
I will enjoy any feedback of the potential drawbacks or errors in this 
patchs. You can refer to the developer mailing list for a little 
discussion about them (the drawbacks and the patchs).
Best regards,
Ludo
PS: Sorry for my english (or for the english language).

Saleem Shafi a écrit:

>To be perfectly honest, i'm not 100% sure this problem is restricted
>to inheritance over multiple tables, but that's the configuration i'm
>running into the problem with.
>
>Here's the setup:  i've got a base class (Role) and a subclass
>(Faculty).  There's a ROLE table and a FACULTY table and it's mapped
>according to the description of option #3 in the guide.  Role defines
>a 1-to-1 relationship with Person and there's a column in the ROLE
>table that corresponds to the pk of the PERSON table.
>
>In the code, i create a Person object and a Faculty object and set the
>reference on Faculty (inherited from Role) to the newly created
>Person.  Depending on how i setup my descriptor for Role, i run into 1
>of 2 problems.  1) If i set the auto-update flag on the Person
>reference descriptor to 'true', i get an SQL exception complaining
>about cannot insert duplicate key on Person because when the Role
>object (added to the transaction when i locked Faculty, i assume to
>handle persisting the necessary information to the ROLE table) tries
>to insert into the Person table in accordance with the auto-update
>flag, but of course, so does the actual Person object.  Or, 2) if i
>set the auto-update flag to false, committing the Role fails because
>of the inability to satisfy the foreign key relationship to Person.
>
>In situation #1, i would expect OJB to recognize that it has already
>inserted the Person object and does not need to do so again; and, in
>situation #2, i would expect the reorder() method in the
>ObjectEnvelopeTable to recognize that the Role needs to be committed
>after Person.  I realize that OJB doesn't know anything about my
>foreign key constraints on the database, but i couldn't find any way
>to explicity define the dependency between the two objects.
>
>Does anyone know of any way around this mess other than dropping the
>foreign key constraint?
>
>
>Saleem.
>
>---------------------------------------------------------------------
>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


Re: more fun with inheritance over multiple tables

Posted by Armin Waibel <ar...@apache.org>.
Hi Saleem,

Saleem Shafi wrote:

> To be perfectly honest, i'm not 100% sure this problem is restricted
> to inheritance over multiple tables, but that's the configuration i'm
> running into the problem with.
> 

Inheritance over multiple tables was currently only supported by the PB-api.

 > Does anyone know of any way around this mess other than dropping the
 > foreign key constraint?
 >

Sorry I don't.
Will try to fix the ODMG-api to support "Inheritance over multiple 
tables" too, but I can't give you a time frame (much other stuff to do). 
Any help would be appreciated ;-)

regards,
Armin


> Here's the setup:  i've got a base class (Role) and a subclass
> (Faculty).  There's a ROLE table and a FACULTY table and it's mapped
> according to the description of option #3 in the guide.  Role defines
> a 1-to-1 relationship with Person and there's a column in the ROLE
> table that corresponds to the pk of the PERSON table.
> 
> In the code, i create a Person object and a Faculty object and set the
> reference on Faculty (inherited from Role) to the newly created
> Person.  Depending on how i setup my descriptor for Role, i run into 1
> of 2 problems.  1) If i set the auto-update flag on the Person
> reference descriptor to 'true', i get an SQL exception complaining
> about cannot insert duplicate key on Person because when the Role
> object (added to the transaction when i locked Faculty, i assume to
> handle persisting the necessary information to the ROLE table) tries
> to insert into the Person table in accordance with the auto-update
> flag, but of course, so does the actual Person object.  Or, 2) if i
> set the auto-update flag to false, committing the Role fails because
> of the inability to satisfy the foreign key relationship to Person.
> 
> In situation #1, i would expect OJB to recognize that it has already
> inserted the Person object and does not need to do so again; and, in
> situation #2, i would expect the reorder() method in the
> ObjectEnvelopeTable to recognize that the Role needs to be committed
> after Person.  I realize that OJB doesn't know anything about my
> foreign key constraints on the database, but i couldn't find any way
> to explicity define the dependency between the two objects.
> 
> Does anyone know of any way around this mess other than dropping the
> foreign key constraint?
> 
> 
> Saleem.
> 
> ---------------------------------------------------------------------
> 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


Re: more fun with inheritance over multiple tables

Posted by Jakob Braeuchi <jb...@gmx.ch>.
hi saleem,

may be it was too late yesterday... of course it must be caused by 
multi-table-inheritance somehow, because my test-case works.

sorry
jakob

Jakob Braeuchi schrieb:

> hi saleem,
> 
> Saleem Shafi schrieb:
> 
>> To be perfectly honest, i'm not 100% sure this problem is restricted
>> to inheritance over multiple tables, but that's the configuration i'm
>> running into the problem with.
> 
> 
> imo this is not a problem caused by multi-table-inheritance. i'm 
> currently working on a testcase using bidirectional references in class 
> ReferenceTest.
> 
>         RefObject a = new ObjA();
>         RefObject b = new ObjB();
> 
>         b.setName(name+"_second_1");
>         a.setName(name+"_first_1");
> 
>         a.setRef(b);
>         b.setRef(a);
> 
>         broker.beginTransaction();
>         broker.store(a);
>         broker.commitTransaction();
> 
> so far i cannot confirm an issue with inserting an object twice (i use 
> no multi-table-inheritance) :
> 
> INSERT INTO REF_OBJ_B (OBJ_ID,NAME,FK_REF) VALUES 
> ('47','testStoreBidirectionalReference_1096487333296_second_1','46')
> INSERT INTO REF_OBJ_A (OBJ_ID,NAME,FK_REF) VALUES 
> ('46','testStoreBidirectionalReference_1096487333296_first_1','47')
> 
> but i also have to admit, that there are no foreign key constraints.
> 
> btw what version are you using ?
> 
> jakob
> 
>>
>> Here's the setup:  i've got a base class (Role) and a subclass
>> (Faculty).  There's a ROLE table and a FACULTY table and it's mapped
>> according to the description of option #3 in the guide.  Role defines
>> a 1-to-1 relationship with Person and there's a column in the ROLE
>> table that corresponds to the pk of the PERSON table.
>>
>> In the code, i create a Person object and a Faculty object and set the
>> reference on Faculty (inherited from Role) to the newly created
>> Person.  Depending on how i setup my descriptor for Role, i run into 1
>> of 2 problems.  1) If i set the auto-update flag on the Person
>> reference descriptor to 'true', i get an SQL exception complaining
>> about cannot insert duplicate key on Person because when the Role
>> object (added to the transaction when i locked Faculty, i assume to
>> handle persisting the necessary information to the ROLE table) tries
>> to insert into the Person table in accordance with the auto-update
>> flag, but of course, so does the actual Person object.  Or, 2) if i
>> set the auto-update flag to false, committing the Role fails because
>> of the inability to satisfy the foreign key relationship to Person.
>>
>> In situation #1, i would expect OJB to recognize that it has already
>> inserted the Person object and does not need to do so again; and, in
>> situation #2, i would expect the reorder() method in the
>> ObjectEnvelopeTable to recognize that the Role needs to be committed
>> after Person.  I realize that OJB doesn't know anything about my
>> foreign key constraints on the database, but i couldn't find any way
>> to explicity define the dependency between the two objects.
>>
>> Does anyone know of any way around this mess other than dropping the
>> foreign key constraint?
>>
>>
>> Saleem.
>>
>> ---------------------------------------------------------------------
>> 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
> 
> 

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


Re: more fun with inheritance over multiple tables

Posted by Jakob Braeuchi <jb...@gmx.ch>.
hi saleem,

forgot to mention that auto-update is true.

jakob


Jakob Braeuchi schrieb:

> hi saleem,
> 
> Saleem Shafi schrieb:
> 
>> To be perfectly honest, i'm not 100% sure this problem is restricted
>> to inheritance over multiple tables, but that's the configuration i'm
>> running into the problem with.
> 
> 
> imo this is not a problem caused by multi-table-inheritance. i'm 
> currently working on a testcase using bidirectional references in class 
> ReferenceTest.
> 
>         RefObject a = new ObjA();
>         RefObject b = new ObjB();
> 
>         b.setName(name+"_second_1");
>         a.setName(name+"_first_1");
> 
>         a.setRef(b);
>         b.setRef(a);
> 
>         broker.beginTransaction();
>         broker.store(a);
>         broker.commitTransaction();
> 
> so far i cannot confirm an issue with inserting an object twice (i use 
> no multi-table-inheritance) :
> 
> INSERT INTO REF_OBJ_B (OBJ_ID,NAME,FK_REF) VALUES 
> ('47','testStoreBidirectionalReference_1096487333296_second_1','46')
> INSERT INTO REF_OBJ_A (OBJ_ID,NAME,FK_REF) VALUES 
> ('46','testStoreBidirectionalReference_1096487333296_first_1','47')
> 
> but i also have to admit, that there are no foreign key constraints.
> 
> btw what version are you using ?
> 
> jakob
> 
>>
>> Here's the setup:  i've got a base class (Role) and a subclass
>> (Faculty).  There's a ROLE table and a FACULTY table and it's mapped
>> according to the description of option #3 in the guide.  Role defines
>> a 1-to-1 relationship with Person and there's a column in the ROLE
>> table that corresponds to the pk of the PERSON table.
>>
>> In the code, i create a Person object and a Faculty object and set the
>> reference on Faculty (inherited from Role) to the newly created
>> Person.  Depending on how i setup my descriptor for Role, i run into 1
>> of 2 problems.  1) If i set the auto-update flag on the Person
>> reference descriptor to 'true', i get an SQL exception complaining
>> about cannot insert duplicate key on Person because when the Role
>> object (added to the transaction when i locked Faculty, i assume to
>> handle persisting the necessary information to the ROLE table) tries
>> to insert into the Person table in accordance with the auto-update
>> flag, but of course, so does the actual Person object.  Or, 2) if i
>> set the auto-update flag to false, committing the Role fails because
>> of the inability to satisfy the foreign key relationship to Person.
>>
>> In situation #1, i would expect OJB to recognize that it has already
>> inserted the Person object and does not need to do so again; and, in
>> situation #2, i would expect the reorder() method in the
>> ObjectEnvelopeTable to recognize that the Role needs to be committed
>> after Person.  I realize that OJB doesn't know anything about my
>> foreign key constraints on the database, but i couldn't find any way
>> to explicity define the dependency between the two objects.
>>
>> Does anyone know of any way around this mess other than dropping the
>> foreign key constraint?
>>
>>
>> Saleem.
>>
>> ---------------------------------------------------------------------
>> 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
> 
> 

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


Re: more fun with inheritance over multiple tables

Posted by Jakob Braeuchi <jb...@gmx.ch>.
hi saleem,

Saleem Shafi schrieb:

> To be perfectly honest, i'm not 100% sure this problem is restricted
> to inheritance over multiple tables, but that's the configuration i'm
> running into the problem with.

imo this is not a problem caused by multi-table-inheritance. i'm currently 
working on a testcase using bidirectional references in class ReferenceTest.

         RefObject a = new ObjA();
         RefObject b = new ObjB();

         b.setName(name+"_second_1");
         a.setName(name+"_first_1");

         a.setRef(b);
         b.setRef(a);

         broker.beginTransaction();
         broker.store(a);
         broker.commitTransaction();

so far i cannot confirm an issue with inserting an object twice (i use no 
multi-table-inheritance) :

INSERT INTO REF_OBJ_B (OBJ_ID,NAME,FK_REF) VALUES 
('47','testStoreBidirectionalReference_1096487333296_second_1','46')
INSERT INTO REF_OBJ_A (OBJ_ID,NAME,FK_REF) VALUES 
('46','testStoreBidirectionalReference_1096487333296_first_1','47')

but i also have to admit, that there are no foreign key constraints.

btw what version are you using ?

jakob

> 
> Here's the setup:  i've got a base class (Role) and a subclass
> (Faculty).  There's a ROLE table and a FACULTY table and it's mapped
> according to the description of option #3 in the guide.  Role defines
> a 1-to-1 relationship with Person and there's a column in the ROLE
> table that corresponds to the pk of the PERSON table.
> 
> In the code, i create a Person object and a Faculty object and set the
> reference on Faculty (inherited from Role) to the newly created
> Person.  Depending on how i setup my descriptor for Role, i run into 1
> of 2 problems.  1) If i set the auto-update flag on the Person
> reference descriptor to 'true', i get an SQL exception complaining
> about cannot insert duplicate key on Person because when the Role
> object (added to the transaction when i locked Faculty, i assume to
> handle persisting the necessary information to the ROLE table) tries
> to insert into the Person table in accordance with the auto-update
> flag, but of course, so does the actual Person object.  Or, 2) if i
> set the auto-update flag to false, committing the Role fails because
> of the inability to satisfy the foreign key relationship to Person.
> 
> In situation #1, i would expect OJB to recognize that it has already
> inserted the Person object and does not need to do so again; and, in
> situation #2, i would expect the reorder() method in the
> ObjectEnvelopeTable to recognize that the Role needs to be committed
> after Person.  I realize that OJB doesn't know anything about my
> foreign key constraints on the database, but i couldn't find any way
> to explicity define the dependency between the two objects.
> 
> Does anyone know of any way around this mess other than dropping the
> foreign key constraint?
> 
> 
> Saleem.
> 
> ---------------------------------------------------------------------
> 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