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: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]





---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to