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 Edson Carlos Ericksson Richter <ed...@mgrinformatica.com.br> on 2004/03/30 16:44:33 UTC

Probleml with Mapping Inheritance Hierarchies

Sorry by reposting, but appear that my last post wasn't to the list...
-----------------------

I can reproduce this problem with OJB 1.0rc6.

Appear that when two or more tables with same PKs, with identical values 
for their PKs have the following behaviour:

a) Get Identity for the first object. Get the object by Identity. Put it 
in the ChainingIterator
b) Get Identity for second object. Since this identity is already 
(remeber, the values of the PKs are the same), don't get the object 
again. Just put it again.
c) and so on.

I don't know if this is the real steps done inside OJB (I tryied to 
debug, but I must admit it's so much complex to me), but as far as I can 
get debugged, is this that is occuring.

I think that the test should be made against the same PK and 
getClass().getName(). If two are same, then the object is already inside 
(and, if user asked for distinct, should not add repeated anyway). 
Otherwise, should exect a getByIdentity using the correct table.

What do you think all?
Can someone test the extent tests using values in different tables with 
same PK?

As workaround, I added ojbConcreteClass to my class-descriptor as PK, 
and works fine (but I think it's a very, really bad solution).
Behaviour is same with or without proxies.

Best regards,

Edson Richter




Edson Carlos Ericksson Richter wrote:

> Hi!
>
> I don't know if this solves your problem, but AFAIK, you can't mix 
> <field-descriptor> with <extent-class>, as you have done in 
> class-descriptor for A class.
>
> More, I have no luck in using extent-class using a Interface as 
> super-object. Have you tried an ABAbstractClass (I'm just trying a 
> sidekick)?
>
> Best regards,
>
> Edson Richter
>
>
> Björn Voigt wrote:
>
>> OK, I have still no solution for my inheritance mapping problem.
>> There are my Classes A,B and C implementing the ABInterface, C and B
>> extend from A. I want to map each class to a distinct tables, but
>> on Multiple Joined Tables. The c an b table have its own primary 
>> column "b_id" and "c_id" and both a foreign key "a_id" referenes the 
>> a table.
>>
>>         Table A:                         Table B:
>>  id | some_value_from_a       b_id | a_id | some_value_from_b
>> ----+-------------------     ------+------+-------------------
>>   1 |              1000        100 |    1 |              1001
>>   2 |              2000
>>
>>                                          Table C:
>>                               c_id | a_id | some_value_from_c
>>                              ------+------+-------------------
>>                                101 |    2 |              2002
>>
>>
>>
>> Ok, if I query the ABInterface I want have two
>> instances, one of B and one of C, something like this:
>>
>>     instance test.B id:1 a_value:1000 b_value:1001
>>     instance test.C id:2 a_value:2000 c_value:2002
>>
>> But I get also instances of A, a query has this result:
>>
>>     instance test.A id:1 a_value:1000
>>     instance test.A id:2 a_value:2000
>>     instance test.B id:1 a_value:1000 b_value:1001
>>     instance test.C id:2 a_value:2000 c_value:2002
>>
>> But thats not all:
>>
>>     instance into b values (1, 1, 1001);   instead of:
>>     instance into b values (100, 1, 1001);
>>
>>     has the following query-result:
>>
>>     instance test.A id:1 a_value:1000
>>     instance test.A id:2 a_value:2000
>>     instance test.A id:1 a_value:1000
>>     instance test.C id:2 a_value:2000 c_value:2002
>>
>> if b_id equals to an id of the a-table, or b_id equals
>> to a c_id in c-table, the result is another.
>>
>> I am using rc5 and would be very happy, if you
>> can help me or give me an working example.
>>
>>
>> Björn Voigt
>>
>>
>> Here follows my complete source code:
>>
>> package test;
>> public class A implements ABInterface{
>>     int id;
>>     int someValueFromA;
>>     public String toString() {
>>         return this.getClass() + " id:" +id +" a_value:" +
>>         someValueFromA;
>>     }
>> }
>>
>> package test;
>> public class B extends A {
>>     int b_id;
>>     int someValueFromB;
>>
>>     public String toString() {
>>         return super.toString() + " b_value:" + someValueFromB;
>>     }
>> }
>>
>> package test;
>> public class C extends A {
>>     int c_id;
>>     int someValueFromC;
>>     public String toString() {
>>         return super.toString() + " c_value:" + someValueFromC;
>>     }
>> }
>>
>> <class-descriptor class="test.ABInterface">
>>   <extent-class class-ref="test.A"/>     <extent-class 
>> class-ref="test.B"/>
>>   <extent-class class-ref="test.C"/>   </class-descriptor>
>>
>> <class-descriptor class="test.A" table="a">
>>   <field-descriptor name="id" column="id" jdbc-type="INTEGER"
>>     primarykey="true" autoincrement="true" />
>>   <field-descriptor name="someValueFromA" 
>> column="some_value_from_a"           jdbc-type="INTEGER" />
>>   <extent-class class-ref="test.B"/>     <extent-class 
>> class-ref="test.C"/>
>> </class-descriptor>
>>
>> <class-descriptor class="test.B" table="b">
>>   <field-descriptor name="b_id" column="b_id" jdbc-type="INTEGER"
>>     primarykey="true" autoincrement="true" />
>>   <field-descriptor name="id" column="a_id" jdbc-type="INTEGER"/>
>>   <field-descriptor name="someValueFromB" 
>> column="some_value_from_b"        jdbc-type="INTEGER"/>
>>   <reference-descriptor name="super" class-ref="test.A">
>>     <foreignkey field-ref="id"/>
>>   </reference-descriptor>
>> </class-descriptor>
>>
>> <class-descriptor class="test.C" table="c">
>>   <field-descriptor name="c_id" column="c_id" jdbc-type="INTEGER"
>>     primarykey="true" autoincrement="true" />
>>   <field-descriptor name="id" column="a_id" jdbc-type="INTEGER"/>
>>   <field-descriptor name="someValueFromC" column="some_value_from_c"
>>     jdbc-type="INTEGER"/>
>>   <reference-descriptor name="super" class-ref="test.A">
>>     <foreignkey field-ref="id"/>
>>   </reference-descriptor>
>> </class-descriptor>
>>
>>
>>
>> ---------------------------------------------------------------------
>> 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: Probleml with Mapping Inheritance Hierarchies

Posted by Edson Carlos Ericksson Richter <ed...@mgrinformatica.com.br>.
Yes, I already have done it.
There is no chance to include the class name into identity object when 
checking the PK id?

Best regards,
Edson Richter


Jakob Braeuchi wrote:

> hi edson,
>
> the Identity uses pk only. so you'd have to declare ojbConcreteClass 
> part of the pk.
>
> jakob
>
> Edson Carlos Ericksson Richter wrote:
>
>> I did it diferencing them by the class name (I put the 
>> ojbConcreteClass - I know this is not really needed, but I think any 
>> identifier is ok).
>> So, there is no chance to OJB identify (by the complete class name) 
>> that the classes are not same for same PK id, and then use correct 
>> class-descriptor and instantiate correct class?
>>
>> Jakob Braeuchi wrote:
>>
>>> hi edson,
>>>
>>> this is imo a know fact. ojb requires to pk to be unique within a 
>>> class hierarchy. let's assume you have a class D referencing 1:1 an 
>>> A identified by
>>> id =1. if this id is not unique in the class hierarchy, then ojb 
>>> does not know if it's an A, B or C. imo there's no other way than to 
>>> define th pk unique.
>>>
>>> jakob
>>>
>>> Edson Carlos Ericksson Richter wrote:
>>>
>>>> Of course, I'll try (all package test).
>>>>
>>>> public class A {
>>>>  public int id;
>>>>  public String description;
>>>> }
>>>>
>>>> public class B extends A {
>>>>  public double value;
>>>> }
>>>>
>>>> public class C extends A {
>>>>  public Date value;
>>>> }
>>>>
>>>> <class-descriptor
>>>>  class="test.A">
>>>>    <extent-class class-ref="test.B" />
>>>>    <extent-class class-ref="test.C" />
>>>> </class-descriptor>
>>>>
>>>> <class-descriptor
>>>>     class="test.B" table="tableB">
>>>>  <field-descriptor
>>>>       name="id"
>>>>       column="id"
>>>>        jdbc-type="INTEGER"
>>>>        primary-key="true"/>
>>>>    <field-descriptor
>>>>        name="description"
>>>>         column="description"
>>>>         jdbc-type="VARCHAR"/>
>>>>    <field-descriptor
>>>>        name="value"
>>>>        column="value"
>>>>         jdbc-type="DOUBLE"/>
>>>> </class-descriptor>
>>>>
>>>>
>>>> <class-descriptor
>>>>     class="test.C" table="tableC">
>>>>  <field-descriptor
>>>>       name="id"
>>>>       column="id"
>>>>        jdbc-type="INTEGER"
>>>>        primary-key="true"/>
>>>>    <field-descriptor
>>>>        name="description"
>>>>         column="description"
>>>>         jdbc-type="VARCHAR"/>
>>>>    <field-descriptor
>>>>        name="value"
>>>>        column="value"
>>>>         
>>>> conversion="org.apache.ojb.broker.accesslayer.conversions.JavaDate2SqlTimestampFieldConversion" 
>>>>
>>>>         jdbc-type="TIMESTAMP"/>
>>>> </class-descriptor>
>>>>
>>>>
>>>> Now fill with data:
>>>>
>>>> insert into tableB (id, description, value) values (1, 'testB1', 
>>>> 123.45)
>>>> insert into tableB (id, description, value) values (2, 'testB2', 
>>>> 234.56)
>>>> insert into tableC (id, description, value) values (1, 'testC1', 
>>>> '2004-04-01 00:00:00.000')
>>>> insert into tableC (id, description, value) values (2, 'testC2', 
>>>> '2004-04-01 00:00:00.000')
>>>>
>>>> Then try to read all with query by criteria, or something, over 
>>>> test.A class. You will get a collection of 4 objects B or 4 objects 
>>>> C (depending what the databased returned first!!!).
>>>>
>>>> The problem here as far as I can see is because either B and C has 
>>>> exactly same PK definition and same values for PKs. As I related, 
>>>> if I add some kind of  field to diferentiate the PK, result is right.
>>>>
>>>> Best regards,
>>>>
>>>> Edson Richter
>>>>
>>>>
>>>>
>>>>
>>>> ---------------------------------------------------------------------
>>>> 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
>>
>>
>
> ---------------------------------------------------------------------
> 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: Probleml with Mapping Inheritance Hierarchies

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

the Identity uses pk only. so you'd have to declare ojbConcreteClass part of the pk.

jakob

Edson Carlos Ericksson Richter wrote:
> I did it diferencing them by the class name (I put the ojbConcreteClass 
> - I know this is not really needed, but I think any identifier is ok).
> So, there is no chance to OJB identify (by the complete class name) that 
> the classes are not same for same PK id, and then use correct 
> class-descriptor and instantiate correct class?
> 
> Jakob Braeuchi wrote:
> 
>> hi edson,
>>
>> this is imo a know fact. ojb requires to pk to be unique within a 
>> class hierarchy. let's assume you have a class D referencing 1:1 an A 
>> identified by
>> id =1. if this id is not unique in the class hierarchy, then ojb does 
>> not know if it's an A, B or C. imo there's no other way than to define 
>> th pk unique.
>>
>> jakob
>>
>> Edson Carlos Ericksson Richter wrote:
>>
>>> Of course, I'll try (all package test).
>>>
>>> public class A {
>>>  public int id;
>>>  public String description;
>>> }
>>>
>>> public class B extends A {
>>>  public double value;
>>> }
>>>
>>> public class C extends A {
>>>  public Date value;
>>> }
>>>
>>> <class-descriptor
>>>  class="test.A">
>>>    <extent-class class-ref="test.B" />
>>>    <extent-class class-ref="test.C" />
>>> </class-descriptor>
>>>
>>> <class-descriptor
>>>     class="test.B" table="tableB">
>>>  <field-descriptor
>>>       name="id"
>>>       column="id"
>>>        jdbc-type="INTEGER"
>>>        primary-key="true"/>
>>>    <field-descriptor
>>>        name="description"
>>>         column="description"
>>>         jdbc-type="VARCHAR"/>
>>>    <field-descriptor
>>>        name="value"
>>>        column="value"
>>>         jdbc-type="DOUBLE"/>
>>> </class-descriptor>
>>>
>>>
>>> <class-descriptor
>>>     class="test.C" table="tableC">
>>>  <field-descriptor
>>>       name="id"
>>>       column="id"
>>>        jdbc-type="INTEGER"
>>>        primary-key="true"/>
>>>    <field-descriptor
>>>        name="description"
>>>         column="description"
>>>         jdbc-type="VARCHAR"/>
>>>    <field-descriptor
>>>        name="value"
>>>        column="value"
>>>         
>>> conversion="org.apache.ojb.broker.accesslayer.conversions.JavaDate2SqlTimestampFieldConversion" 
>>>
>>>         jdbc-type="TIMESTAMP"/>
>>> </class-descriptor>
>>>
>>>
>>> Now fill with data:
>>>
>>> insert into tableB (id, description, value) values (1, 'testB1', 123.45)
>>> insert into tableB (id, description, value) values (2, 'testB2', 234.56)
>>> insert into tableC (id, description, value) values (1, 'testC1', 
>>> '2004-04-01 00:00:00.000')
>>> insert into tableC (id, description, value) values (2, 'testC2', 
>>> '2004-04-01 00:00:00.000')
>>>
>>> Then try to read all with query by criteria, or something, over 
>>> test.A class. You will get a collection of 4 objects B or 4 objects C 
>>> (depending what the databased returned first!!!).
>>>
>>> The problem here as far as I can see is because either B and C has 
>>> exactly same PK definition and same values for PKs. As I related, if 
>>> I add some kind of  field to diferentiate the PK, result is right.
>>>
>>> Best regards,
>>>
>>> Edson Richter
>>>
>>>
>>>
>>>
>>> ---------------------------------------------------------------------
>>> 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
> 
> 

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


Re: Probleml with Mapping Inheritance Hierarchies

Posted by Edson Carlos Ericksson Richter <ed...@mgrinformatica.com.br>.
I did it diferencing them by the class name (I put the ojbConcreteClass 
- I know this is not really needed, but I think any identifier is ok).
So, there is no chance to OJB identify (by the complete class name) that 
the classes are not same for same PK id, and then use correct 
class-descriptor and instantiate correct class?

Jakob Braeuchi wrote:

> hi edson,
>
> this is imo a know fact. ojb requires to pk to be unique within a 
> class hierarchy. let's assume you have a class D referencing 1:1 an A 
> identified by
> id =1. if this id is not unique in the class hierarchy, then ojb does 
> not know if it's an A, B or C. imo there's no other way than to define 
> th pk unique.
>
> jakob
>
> Edson Carlos Ericksson Richter wrote:
>
>> Of course, I'll try (all package test).
>>
>> public class A {
>>  public int id;
>>  public String description;
>> }
>>
>> public class B extends A {
>>  public double value;
>> }
>>
>> public class C extends A {
>>  public Date value;
>> }
>>
>> <class-descriptor
>>  class="test.A">
>>    <extent-class class-ref="test.B" />
>>    <extent-class class-ref="test.C" />
>> </class-descriptor>
>>
>> <class-descriptor
>>     class="test.B" table="tableB">
>>  <field-descriptor
>>       name="id"
>>       column="id"
>>        jdbc-type="INTEGER"
>>        primary-key="true"/>
>>    <field-descriptor
>>        name="description"
>>         column="description"
>>         jdbc-type="VARCHAR"/>
>>    <field-descriptor
>>        name="value"
>>        column="value"
>>         jdbc-type="DOUBLE"/>
>> </class-descriptor>
>>
>>
>> <class-descriptor
>>     class="test.C" table="tableC">
>>  <field-descriptor
>>       name="id"
>>       column="id"
>>        jdbc-type="INTEGER"
>>        primary-key="true"/>
>>    <field-descriptor
>>        name="description"
>>         column="description"
>>         jdbc-type="VARCHAR"/>
>>    <field-descriptor
>>        name="value"
>>        column="value"
>>         
>> conversion="org.apache.ojb.broker.accesslayer.conversions.JavaDate2SqlTimestampFieldConversion" 
>>
>>         jdbc-type="TIMESTAMP"/>
>> </class-descriptor>
>>
>>
>> Now fill with data:
>>
>> insert into tableB (id, description, value) values (1, 'testB1', 123.45)
>> insert into tableB (id, description, value) values (2, 'testB2', 234.56)
>> insert into tableC (id, description, value) values (1, 'testC1', 
>> '2004-04-01 00:00:00.000')
>> insert into tableC (id, description, value) values (2, 'testC2', 
>> '2004-04-01 00:00:00.000')
>>
>> Then try to read all with query by criteria, or something, over 
>> test.A class. You will get a collection of 4 objects B or 4 objects C 
>> (depending what the databased returned first!!!).
>>
>> The problem here as far as I can see is because either B and C has 
>> exactly same PK definition and same values for PKs. As I related, if 
>> I add some kind of  field to diferentiate the PK, result is right.
>>
>> Best regards,
>>
>> Edson Richter
>>
>>
>>
>>
>> ---------------------------------------------------------------------
>> 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: Probleml with Mapping Inheritance Hierarchies

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

this is imo a know fact. ojb requires to pk to be unique within a class 
hierarchy. let's assume you have a class D referencing 1:1 an A identified by
id =1. if this id is not unique in the class hierarchy, then ojb does not know 
if it's an A, B or C. imo there's no other way than to define th pk unique.

jakob

Edson Carlos Ericksson Richter wrote:

> Of course, I'll try (all package test).
> 
> public class A {
>  public int id;
>  public String description;
> }
> 
> public class B extends A {
>  public double value;
> }
> 
> public class C extends A {
>  public Date value;
> }
> 
> <class-descriptor
>  class="test.A">
>    <extent-class class-ref="test.B" />
>    <extent-class class-ref="test.C" />
> </class-descriptor>
> 
> <class-descriptor
>     class="test.B" table="tableB">
>  <field-descriptor
>       name="id"
>       column="id"
>        jdbc-type="INTEGER"
>        primary-key="true"/>
>    <field-descriptor
>        name="description"
>         column="description"
>         jdbc-type="VARCHAR"/>
>    <field-descriptor
>        name="value"
>        column="value"
>         jdbc-type="DOUBLE"/>
> </class-descriptor>
> 
> 
> <class-descriptor
>     class="test.C" table="tableC">
>  <field-descriptor
>       name="id"
>       column="id"
>        jdbc-type="INTEGER"
>        primary-key="true"/>
>    <field-descriptor
>        name="description"
>         column="description"
>         jdbc-type="VARCHAR"/>
>    <field-descriptor
>        name="value"
>        column="value"
>         
> conversion="org.apache.ojb.broker.accesslayer.conversions.JavaDate2SqlTimestampFieldConversion" 
> 
>         jdbc-type="TIMESTAMP"/>
> </class-descriptor>
> 
> 
> Now fill with data:
> 
> insert into tableB (id, description, value) values (1, 'testB1', 123.45)
> insert into tableB (id, description, value) values (2, 'testB2', 234.56)
> insert into tableC (id, description, value) values (1, 'testC1', 
> '2004-04-01 00:00:00.000')
> insert into tableC (id, description, value) values (2, 'testC2', 
> '2004-04-01 00:00:00.000')
> 
> Then try to read all with query by criteria, or something, over test.A 
> class. You will get a collection of 4 objects B or 4 objects C 
> (depending what the databased returned first!!!).
> 
> The problem here as far as I can see is because either B and C has 
> exactly same PK definition and same values for PKs. As I related, if I 
> add some kind of  field to diferentiate the PK, result is right.
> 
> Best regards,
> 
> Edson Richter
> 
> 
> 
> 
> ---------------------------------------------------------------------
> 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: Probleml with Mapping Inheritance Hierarchies

Posted by Edson Carlos Ericksson Richter <ed...@mgrinformatica.com.br>.
Of course, I'll try (all package test).

public class A {
  public int id;
  public String description;
}

public class B extends A {
  public double value;
}

public class C extends A {
  public Date value;
}

<class-descriptor
  class="test.A">
    <extent-class class-ref="test.B" />
    <extent-class class-ref="test.C" />
</class-descriptor>

<class-descriptor
     class="test.B" table="tableB">
  <field-descriptor
       name="id"
       column="id"
        jdbc-type="INTEGER"
        primary-key="true"/>
    <field-descriptor
        name="description"
         column="description"
         jdbc-type="VARCHAR"/>
    <field-descriptor
        name="value"
        column="value"
         jdbc-type="DOUBLE"/>
</class-descriptor>


<class-descriptor
     class="test.C" table="tableC">
  <field-descriptor
       name="id"
       column="id"
        jdbc-type="INTEGER"
        primary-key="true"/>
    <field-descriptor
        name="description"
         column="description"
         jdbc-type="VARCHAR"/>
    <field-descriptor
        name="value"
        column="value"
         
conversion="org.apache.ojb.broker.accesslayer.conversions.JavaDate2SqlTimestampFieldConversion"
         jdbc-type="TIMESTAMP"/>
</class-descriptor>


Now fill with data:

insert into tableB (id, description, value) values (1, 'testB1', 123.45)
insert into tableB (id, description, value) values (2, 'testB2', 234.56)
insert into tableC (id, description, value) values (1, 'testC1', 
'2004-04-01 00:00:00.000')
insert into tableC (id, description, value) values (2, 'testC2', 
'2004-04-01 00:00:00.000')

Then try to read all with query by criteria, or something, over test.A 
class. You will get a collection of 4 objects B or 4 objects C 
(depending what the databased returned first!!!).

The problem here as far as I can see is because either B and C has 
exactly same PK definition and same values for PKs. As I related, if I 
add some kind of  field to diferentiate the PK, result is right.

Best regards,

Edson Richter




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


Re: Probleml with Mapping Inheritance Hierarchies

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

can you send me an test case for this problem? Or can you describe how 
the test case should look like?

regards,
Armin

Edson Carlos Ericksson Richter wrote:

> Sorry by reposting, but appear that my last post wasn't to the list...
> -----------------------
> 
> I can reproduce this problem with OJB 1.0rc6.
> 
> Appear that when two or more tables with same PKs, with identical values 
> for their PKs have the following behaviour:
> 
> a) Get Identity for the first object. Get the object by Identity. Put it 
> in the ChainingIterator
> b) Get Identity for second object. Since this identity is already 
> (remeber, the values of the PKs are the same), don't get the object 
> again. Just put it again.
> c) and so on.
> 
> I don't know if this is the real steps done inside OJB (I tryied to 
> debug, but I must admit it's so much complex to me), but as far as I can 
> get debugged, is this that is occuring.
> 
> I think that the test should be made against the same PK and 
> getClass().getName(). If two are same, then the object is already inside 
> (and, if user asked for distinct, should not add repeated anyway). 
> Otherwise, should exect a getByIdentity using the correct table.
> 
> What do you think all?
> Can someone test the extent tests using values in different tables with 
> same PK?
> 
> As workaround, I added ojbConcreteClass to my class-descriptor as PK, 
> and works fine (but I think it's a very, really bad solution).
> Behaviour is same with or without proxies.
> 
> Best regards,
> 
> Edson Richter
> 
> 
> 
> 
> Edson Carlos Ericksson Richter wrote:
> 
>> Hi!
>>
>> I don't know if this solves your problem, but AFAIK, you can't mix 
>> <field-descriptor> with <extent-class>, as you have done in 
>> class-descriptor for A class.
>>
>> More, I have no luck in using extent-class using a Interface as 
>> super-object. Have you tried an ABAbstractClass (I'm just trying a 
>> sidekick)?
>>
>> Best regards,
>>
>> Edson Richter
>>
>>
>> Björn Voigt wrote:
>>
>>> OK, I have still no solution for my inheritance mapping problem.
>>> There are my Classes A,B and C implementing the ABInterface, C and B
>>> extend from A. I want to map each class to a distinct tables, but
>>> on Multiple Joined Tables. The c an b table have its own primary 
>>> column "b_id" and "c_id" and both a foreign key "a_id" referenes the 
>>> a table.
>>>
>>>         Table A:                         Table B:
>>>  id | some_value_from_a       b_id | a_id | some_value_from_b
>>> ----+-------------------     ------+------+-------------------
>>>   1 |              1000        100 |    1 |              1001
>>>   2 |              2000
>>>
>>>                                          Table C:
>>>                               c_id | a_id | some_value_from_c
>>>                              ------+------+-------------------
>>>                                101 |    2 |              2002
>>>
>>>
>>>
>>> Ok, if I query the ABInterface I want have two
>>> instances, one of B and one of C, something like this:
>>>
>>>     instance test.B id:1 a_value:1000 b_value:1001
>>>     instance test.C id:2 a_value:2000 c_value:2002
>>>
>>> But I get also instances of A, a query has this result:
>>>
>>>     instance test.A id:1 a_value:1000
>>>     instance test.A id:2 a_value:2000
>>>     instance test.B id:1 a_value:1000 b_value:1001
>>>     instance test.C id:2 a_value:2000 c_value:2002
>>>
>>> But thats not all:
>>>
>>>     instance into b values (1, 1, 1001);   instead of:
>>>     instance into b values (100, 1, 1001);
>>>
>>>     has the following query-result:
>>>
>>>     instance test.A id:1 a_value:1000
>>>     instance test.A id:2 a_value:2000
>>>     instance test.A id:1 a_value:1000
>>>     instance test.C id:2 a_value:2000 c_value:2002
>>>
>>> if b_id equals to an id of the a-table, or b_id equals
>>> to a c_id in c-table, the result is another.
>>>
>>> I am using rc5 and would be very happy, if you
>>> can help me or give me an working example.
>>>
>>>
>>> Björn Voigt
>>>
>>>
>>> Here follows my complete source code:
>>>
>>> package test;
>>> public class A implements ABInterface{
>>>     int id;
>>>     int someValueFromA;
>>>     public String toString() {
>>>         return this.getClass() + " id:" +id +" a_value:" +
>>>         someValueFromA;
>>>     }
>>> }
>>>
>>> package test;
>>> public class B extends A {
>>>     int b_id;
>>>     int someValueFromB;
>>>
>>>     public String toString() {
>>>         return super.toString() + " b_value:" + someValueFromB;
>>>     }
>>> }
>>>
>>> package test;
>>> public class C extends A {
>>>     int c_id;
>>>     int someValueFromC;
>>>     public String toString() {
>>>         return super.toString() + " c_value:" + someValueFromC;
>>>     }
>>> }
>>>
>>> <class-descriptor class="test.ABInterface">
>>>   <extent-class class-ref="test.A"/>     <extent-class 
>>> class-ref="test.B"/>
>>>   <extent-class class-ref="test.C"/>   </class-descriptor>
>>>
>>> <class-descriptor class="test.A" table="a">
>>>   <field-descriptor name="id" column="id" jdbc-type="INTEGER"
>>>     primarykey="true" autoincrement="true" />
>>>   <field-descriptor name="someValueFromA" 
>>> column="some_value_from_a"           jdbc-type="INTEGER" />
>>>   <extent-class class-ref="test.B"/>     <extent-class 
>>> class-ref="test.C"/>
>>> </class-descriptor>
>>>
>>> <class-descriptor class="test.B" table="b">
>>>   <field-descriptor name="b_id" column="b_id" jdbc-type="INTEGER"
>>>     primarykey="true" autoincrement="true" />
>>>   <field-descriptor name="id" column="a_id" jdbc-type="INTEGER"/>
>>>   <field-descriptor name="someValueFromB" 
>>> column="some_value_from_b"        jdbc-type="INTEGER"/>
>>>   <reference-descriptor name="super" class-ref="test.A">
>>>     <foreignkey field-ref="id"/>
>>>   </reference-descriptor>
>>> </class-descriptor>
>>>
>>> <class-descriptor class="test.C" table="c">
>>>   <field-descriptor name="c_id" column="c_id" jdbc-type="INTEGER"
>>>     primarykey="true" autoincrement="true" />
>>>   <field-descriptor name="id" column="a_id" jdbc-type="INTEGER"/>
>>>   <field-descriptor name="someValueFromC" column="some_value_from_c"
>>>     jdbc-type="INTEGER"/>
>>>   <reference-descriptor name="super" class-ref="test.A">
>>>     <foreignkey field-ref="id"/>
>>>   </reference-descriptor>
>>> </class-descriptor>
>>>
>>>
>>>
>>> ---------------------------------------------------------------------
>>> 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
> 
> 
> 

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