You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-dev@db.apache.org by Martin Taal <mt...@springsite.com> on 2005/04/19 18:53:53 UTC

ojb 1.1: Discriminator-descriptor issue

Hi,
When I have a class hierarchy mapped to multiple (joined) tables then I
am not sure how to use the discriminator-descriptor. At least in the way
I try it it doesn't work.
An example I have a class A and its subclass B.
A is stored in table A and the subclass part of B is stored in table B. 
So get B a join has to be made between tables A and B.

In A I have a discriminator field (specified in the 
discriminator-descriptor).

I store one A and one B object creating two records in the A table and 
one in the B table. This is correct. The discriminator field in the A 
table however only contains the classname of A (for both records). This 
I think is not correct, for the B record it should contain the classname 
of B.

Also when I then retrieve all A objects I get two objects both of type A 
while one of the A object should actually be an instance of B.

Btw, in the case that I store the classhierarchy in one table then the 
above works fine.

As I am looking at the 1.1 branche I am not sure if this part is yet 
completely finished?
Maybe also my setup maybe wrong, see the repository.xml here:

<!-- class: org.elver.store.test.testcasesimple2.A in table: A -->
<class-descriptor class="org.elver.store.test.testcasesimple2.A" table="A">

	<discriminator-descriptor column="A_classname" jdbc-type="VARCHAR" 
value="org.elver.store.test.testcasesimple2.A"/>

	<field-descriptor  name="name" column="name" jdbc-type="VARCHAR" 
nullable="true"/>
	<field-descriptor  name="ID" column="ID" jdbc-type="INTEGER" 
primarykey="true" autoincrement="true" access="anonymous"/>

</class-descriptor>

<!-- class: org.elver.store.test.testcasesimple2.B in table: B -->
<class-descriptor class="org.elver.store.test.testcasesimple2.B" table="B">

	<discriminator-descriptor column="B_classname" jdbc-type="VARCHAR" 
value="org.elver.store.test.testcasesimple2.B"/>

	<field-descriptor  name="nameb" column="nameb" jdbc-type="VARCHAR" 
nullable="true"/>

	<field-descriptor  name="A_ID" column="A_ID" jdbc-type="INTEGER" 
primarykey="true" access="anonymous"/>

	<reference-descriptor name="super" 
class-ref="org.elver.store.test.testcasesimple2.A" auto-retrieve="true" 
auto-update="true" auto-delete="true">
		<foreignkey field-ref="A_ID" />
	</reference-descriptor>

</class-descriptor>

-- 

With Regards, Martin Taal

Springsite
Barchman Wuytierslaan 72b
3818 LK Amersfoort
tel: +31 (0)33 462 02 07
fax: +31 (0)33 463 77 12
Mobile: +31 (0)6 288 48 943
email: mtaal@springsite.com
web: www.springsite.com


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


Re: ojb 1.1: Discriminator-descriptor issue

Posted by Martin Taal <mt...@springsite.com>.
Hi Jakob,
What I understand from multiple joined tables:
If I have a class A with a subclass B, where A is stored in TableA and 
the subclass part of B is stored in TableB. Then the superclass part of 
B is stored TableA and the subclass part in TableB. A objects are stored 
in TableA also. So in this case different classes are saved in one table 
also (nl. the A part of B and A objects themselves in TableA) and a 
discriminator can help to identify which class the record is.
It is just something I noticed because querying on this structure only 
returns A object and never B objects. This has been entered as another 
issue by someone else.

Please correct me If I mix up different concepts here.

Btw, I will be away for 2 weeks so if I do not react after this then you 
know why (I will sitting behind my laptop for another hour or so).

gr. Martin

Jakob Braeuchi wrote:
> hi martin,
> 
> i think you are mixing different mapping strategies. if class is mapped 
> to multiple joined tables why do you then store multiple classes in the 
> same table (that's what the discriminator is for) ?
> 
> jakob
> 
> Martin Taal schrieb:
> 
>> Hi Jakob,
>> The discriminator value is correct in case the classes are mapped to 
>> separate tables. Also in the case that the hierarchy is stored in one 
>> table then it works correctly. So only in case of the joined table it 
>> goes wrong.
>>
>> I can see in the ojb source code that it uses the value specified in 
>> the discriminator (or its classdescriptor) to put in the classname 
>> column (while it should use the class of the live object). It is 
>> strange that in the case everything is stored in one table that it 
>> then works correctly.
>> Btw I am looking and testing against the 1.1 cvs branche.
>>
>> I gues that solving this could also help the query issue just reported 
>> by other also (and mentioned in your release notes as noted in the 
>> mailing list :-).
>>
>> gr. Martin
>>
>> Jakob Braeuchi wrote:
>>
>>> hi martin,
>>>
>>> is the discriminator also wrong when the classes are mapped to 
>>> separate tables ?
>>> ojb has some issues with multi-mapped tables and armin is working on 
>>> a testcase.
>>>
>>> jakob
>>>
>>> Martin Taal schrieb:
>>>
>>>> Hi,
>>>> When I have a class hierarchy mapped to multiple (joined) tables then I
>>>> am not sure how to use the discriminator-descriptor. At least in the 
>>>> way
>>>> I try it it doesn't work.
>>>> An example I have a class A and its subclass B.
>>>> A is stored in table A and the subclass part of B is stored in table 
>>>> B. So get B a join has to be made between tables A and B.
>>>>
>>>> In A I have a discriminator field (specified in the 
>>>> discriminator-descriptor).
>>>>
>>>> I store one A and one B object creating two records in the A table 
>>>> and one in the B table. This is correct. The discriminator field in 
>>>> the A table however only contains the classname of A (for both 
>>>> records). This I think is not correct, for the B record it should 
>>>> contain the classname of B.
>>>>
>>>> Also when I then retrieve all A objects I get two objects both of 
>>>> type A while one of the A object should actually be an instance of B.
>>>>
>>>> Btw, in the case that I store the classhierarchy in one table then 
>>>> the above works fine.
>>>>
>>>> As I am looking at the 1.1 branche I am not sure if this part is yet 
>>>> completely finished?
>>>> Maybe also my setup maybe wrong, see the repository.xml here:
>>>>
>>>> <!-- class: org.elver.store.test.testcasesimple2.A in table: A -->
>>>> <class-descriptor class="org.elver.store.test.testcasesimple2.A" 
>>>> table="A">
>>>>
>>>>     <discriminator-descriptor column="A_classname" 
>>>> jdbc-type="VARCHAR" value="org.elver.store.test.testcasesimple2.A"/>
>>>>
>>>>     <field-descriptor  name="name" column="name" jdbc-type="VARCHAR" 
>>>> nullable="true"/>
>>>>     <field-descriptor  name="ID" column="ID" jdbc-type="INTEGER" 
>>>> primarykey="true" autoincrement="true" access="anonymous"/>
>>>>
>>>> </class-descriptor>
>>>>
>>>> <!-- class: org.elver.store.test.testcasesimple2.B in table: B -->
>>>> <class-descriptor class="org.elver.store.test.testcasesimple2.B" 
>>>> table="B">
>>>>
>>>>     <discriminator-descriptor column="B_classname" 
>>>> jdbc-type="VARCHAR" value="org.elver.store.test.testcasesimple2.B"/>
>>>>
>>>>     <field-descriptor  name="nameb" column="nameb" 
>>>> jdbc-type="VARCHAR" nullable="true"/>
>>>>
>>>>     <field-descriptor  name="A_ID" column="A_ID" jdbc-type="INTEGER" 
>>>> primarykey="true" access="anonymous"/>
>>>>
>>>>     <reference-descriptor name="super" 
>>>> class-ref="org.elver.store.test.testcasesimple2.A" 
>>>> auto-retrieve="true" auto-update="true" auto-delete="true">
>>>>         <foreignkey field-ref="A_ID" />
>>>>     </reference-descriptor>
>>>>
>>>> </class-descriptor>
>>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
>>> For additional commands, e-mail: ojb-dev-help@db.apache.org
>>>
>>>
>>>
>>
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-dev-help@db.apache.org
> 
> 
> 

-- 

With Regards, Martin Taal

Springsite
Barchman Wuytierslaan 72b
3818 LK Amersfoort
tel: +31 (0)33 462 02 07
fax: +31 (0)33 463 77 12
Mobile: +31 (0)6 288 48 943
email: mtaal@springsite.com
web: www.springsite.com

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


Re: ojb 1.1: Discriminator-descriptor issue

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

i think you are mixing different mapping strategies. if class is mapped 
to multiple joined tables why do you then store multiple classes in the 
same table (that's what the discriminator is for) ?

jakob

Martin Taal schrieb:
> Hi Jakob,
> The discriminator value is correct in case the classes are mapped to 
> separate tables. Also in the case that the hierarchy is stored in one 
> table then it works correctly. So only in case of the joined table it 
> goes wrong.
> 
> I can see in the ojb source code that it uses the value specified in the 
> discriminator (or its classdescriptor) to put in the classname column 
> (while it should use the class of the live object). It is strange that 
> in the case everything is stored in one table that it then works correctly.
> Btw I am looking and testing against the 1.1 cvs branche.
> 
> I gues that solving this could also help the query issue just reported 
> by other also (and mentioned in your release notes as noted in the 
> mailing list :-).
> 
> gr. Martin
> 
> Jakob Braeuchi wrote:
> 
>> hi martin,
>>
>> is the discriminator also wrong when the classes are mapped to 
>> separate tables ?
>> ojb has some issues with multi-mapped tables and armin is working on a 
>> testcase.
>>
>> jakob
>>
>> Martin Taal schrieb:
>>
>>> Hi,
>>> When I have a class hierarchy mapped to multiple (joined) tables then I
>>> am not sure how to use the discriminator-descriptor. At least in the way
>>> I try it it doesn't work.
>>> An example I have a class A and its subclass B.
>>> A is stored in table A and the subclass part of B is stored in table 
>>> B. So get B a join has to be made between tables A and B.
>>>
>>> In A I have a discriminator field (specified in the 
>>> discriminator-descriptor).
>>>
>>> I store one A and one B object creating two records in the A table 
>>> and one in the B table. This is correct. The discriminator field in 
>>> the A table however only contains the classname of A (for both 
>>> records). This I think is not correct, for the B record it should 
>>> contain the classname of B.
>>>
>>> Also when I then retrieve all A objects I get two objects both of 
>>> type A while one of the A object should actually be an instance of B.
>>>
>>> Btw, in the case that I store the classhierarchy in one table then 
>>> the above works fine.
>>>
>>> As I am looking at the 1.1 branche I am not sure if this part is yet 
>>> completely finished?
>>> Maybe also my setup maybe wrong, see the repository.xml here:
>>>
>>> <!-- class: org.elver.store.test.testcasesimple2.A in table: A -->
>>> <class-descriptor class="org.elver.store.test.testcasesimple2.A" 
>>> table="A">
>>>
>>>     <discriminator-descriptor column="A_classname" 
>>> jdbc-type="VARCHAR" value="org.elver.store.test.testcasesimple2.A"/>
>>>
>>>     <field-descriptor  name="name" column="name" jdbc-type="VARCHAR" 
>>> nullable="true"/>
>>>     <field-descriptor  name="ID" column="ID" jdbc-type="INTEGER" 
>>> primarykey="true" autoincrement="true" access="anonymous"/>
>>>
>>> </class-descriptor>
>>>
>>> <!-- class: org.elver.store.test.testcasesimple2.B in table: B -->
>>> <class-descriptor class="org.elver.store.test.testcasesimple2.B" 
>>> table="B">
>>>
>>>     <discriminator-descriptor column="B_classname" 
>>> jdbc-type="VARCHAR" value="org.elver.store.test.testcasesimple2.B"/>
>>>
>>>     <field-descriptor  name="nameb" column="nameb" 
>>> jdbc-type="VARCHAR" nullable="true"/>
>>>
>>>     <field-descriptor  name="A_ID" column="A_ID" jdbc-type="INTEGER" 
>>> primarykey="true" access="anonymous"/>
>>>
>>>     <reference-descriptor name="super" 
>>> class-ref="org.elver.store.test.testcasesimple2.A" 
>>> auto-retrieve="true" auto-update="true" auto-delete="true">
>>>         <foreignkey field-ref="A_ID" />
>>>     </reference-descriptor>
>>>
>>> </class-descriptor>
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
>> For additional commands, e-mail: ojb-dev-help@db.apache.org
>>
>>
>>
> 

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


Re: ojb 1.1: Discriminator-descriptor issue

Posted by Martin Taal <mt...@springsite.com>.
Hi Jakob,
The discriminator value is correct in case the classes are mapped to 
separate tables. Also in the case that the hierarchy is stored in one 
table then it works correctly. So only in case of the joined table it 
goes wrong.

I can see in the ojb source code that it uses the value specified in the 
discriminator (or its classdescriptor) to put in the classname column 
(while it should use the class of the live object). It is strange that 
in the case everything is stored in one table that it then works correctly.
Btw I am looking and testing against the 1.1 cvs branche.

I gues that solving this could also help the query issue just reported 
by other also (and mentioned in your release notes as noted in the 
mailing list :-).

gr. Martin

Jakob Braeuchi wrote:
> hi martin,
> 
> is the discriminator also wrong when the classes are mapped to separate 
> tables ?
> ojb has some issues with multi-mapped tables and armin is working on a 
> testcase.
> 
> jakob
> 
> Martin Taal schrieb:
> 
>> Hi,
>> When I have a class hierarchy mapped to multiple (joined) tables then I
>> am not sure how to use the discriminator-descriptor. At least in the way
>> I try it it doesn't work.
>> An example I have a class A and its subclass B.
>> A is stored in table A and the subclass part of B is stored in table 
>> B. So get B a join has to be made between tables A and B.
>>
>> In A I have a discriminator field (specified in the 
>> discriminator-descriptor).
>>
>> I store one A and one B object creating two records in the A table and 
>> one in the B table. This is correct. The discriminator field in the A 
>> table however only contains the classname of A (for both records). 
>> This I think is not correct, for the B record it should contain the 
>> classname of B.
>>
>> Also when I then retrieve all A objects I get two objects both of type 
>> A while one of the A object should actually be an instance of B.
>>
>> Btw, in the case that I store the classhierarchy in one table then the 
>> above works fine.
>>
>> As I am looking at the 1.1 branche I am not sure if this part is yet 
>> completely finished?
>> Maybe also my setup maybe wrong, see the repository.xml here:
>>
>> <!-- class: org.elver.store.test.testcasesimple2.A in table: A -->
>> <class-descriptor class="org.elver.store.test.testcasesimple2.A" 
>> table="A">
>>
>>     <discriminator-descriptor column="A_classname" jdbc-type="VARCHAR" 
>> value="org.elver.store.test.testcasesimple2.A"/>
>>
>>     <field-descriptor  name="name" column="name" jdbc-type="VARCHAR" 
>> nullable="true"/>
>>     <field-descriptor  name="ID" column="ID" jdbc-type="INTEGER" 
>> primarykey="true" autoincrement="true" access="anonymous"/>
>>
>> </class-descriptor>
>>
>> <!-- class: org.elver.store.test.testcasesimple2.B in table: B -->
>> <class-descriptor class="org.elver.store.test.testcasesimple2.B" 
>> table="B">
>>
>>     <discriminator-descriptor column="B_classname" jdbc-type="VARCHAR" 
>> value="org.elver.store.test.testcasesimple2.B"/>
>>
>>     <field-descriptor  name="nameb" column="nameb" jdbc-type="VARCHAR" 
>> nullable="true"/>
>>
>>     <field-descriptor  name="A_ID" column="A_ID" jdbc-type="INTEGER" 
>> primarykey="true" access="anonymous"/>
>>
>>     <reference-descriptor name="super" 
>> class-ref="org.elver.store.test.testcasesimple2.A" 
>> auto-retrieve="true" auto-update="true" auto-delete="true">
>>         <foreignkey field-ref="A_ID" />
>>     </reference-descriptor>
>>
>> </class-descriptor>
>>
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-dev-help@db.apache.org
> 
> 
> 

-- 

With Regards, Martin Taal

Springsite
Barchman Wuytierslaan 72b
3818 LK Amersfoort
tel: +31 (0)33 462 02 07
fax: +31 (0)33 463 77 12
Mobile: +31 (0)6 288 48 943
email: mtaal@springsite.com
web: www.springsite.com

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


Re: ojb 1.1: Discriminator-descriptor issue

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

is the discriminator also wrong when the classes are mapped to separate 
tables ?
ojb has some issues with multi-mapped tables and armin is working on a 
testcase.

jakob

Martin Taal schrieb:
> Hi,
> When I have a class hierarchy mapped to multiple (joined) tables then I
> am not sure how to use the discriminator-descriptor. At least in the way
> I try it it doesn't work.
> An example I have a class A and its subclass B.
> A is stored in table A and the subclass part of B is stored in table B. 
> So get B a join has to be made between tables A and B.
> 
> In A I have a discriminator field (specified in the 
> discriminator-descriptor).
> 
> I store one A and one B object creating two records in the A table and 
> one in the B table. This is correct. The discriminator field in the A 
> table however only contains the classname of A (for both records). This 
> I think is not correct, for the B record it should contain the classname 
> of B.
> 
> Also when I then retrieve all A objects I get two objects both of type A 
> while one of the A object should actually be an instance of B.
> 
> Btw, in the case that I store the classhierarchy in one table then the 
> above works fine.
> 
> As I am looking at the 1.1 branche I am not sure if this part is yet 
> completely finished?
> Maybe also my setup maybe wrong, see the repository.xml here:
> 
> <!-- class: org.elver.store.test.testcasesimple2.A in table: A -->
> <class-descriptor class="org.elver.store.test.testcasesimple2.A" table="A">
> 
>     <discriminator-descriptor column="A_classname" jdbc-type="VARCHAR" 
> value="org.elver.store.test.testcasesimple2.A"/>
> 
>     <field-descriptor  name="name" column="name" jdbc-type="VARCHAR" 
> nullable="true"/>
>     <field-descriptor  name="ID" column="ID" jdbc-type="INTEGER" 
> primarykey="true" autoincrement="true" access="anonymous"/>
> 
> </class-descriptor>
> 
> <!-- class: org.elver.store.test.testcasesimple2.B in table: B -->
> <class-descriptor class="org.elver.store.test.testcasesimple2.B" table="B">
> 
>     <discriminator-descriptor column="B_classname" jdbc-type="VARCHAR" 
> value="org.elver.store.test.testcasesimple2.B"/>
> 
>     <field-descriptor  name="nameb" column="nameb" jdbc-type="VARCHAR" 
> nullable="true"/>
> 
>     <field-descriptor  name="A_ID" column="A_ID" jdbc-type="INTEGER" 
> primarykey="true" access="anonymous"/>
> 
>     <reference-descriptor name="super" 
> class-ref="org.elver.store.test.testcasesimple2.A" auto-retrieve="true" 
> auto-update="true" auto-delete="true">
>         <foreignkey field-ref="A_ID" />
>     </reference-descriptor>
> 
> </class-descriptor>
> 

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