I have a problem to map Inheritance Hierarchies, I'am the using the third proposal of the tutoriala and mapping each class to a distinct table.
I have the following Classes:
1. A and B implements ABInterface 2. B extends A
public class A implements ABInterface{
int id;
int someValueFromA; public String toString() {
return this.getClass() + " id:" +id +" a_value:" + someValueFromA;
}
}public class B extends A {
int id;
int someValueFromB; public String toString() {
return super.toString() + " b_value:" + someValueFromB;
}
}My Mapping looks so:
<class-descriptor class="test.ABInterface"> <extent-class class-ref="test.A"/> <extent-class class-ref="test.B"/> </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"/>
</class-descriptor>
<class-descriptor class="test.B" table="b">
<field-descriptor name="id" column="a_id" jdbc-type="INTEGER" primarykey="true" autoincrement="true" />
<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>
And the table looks:
CREATE TABLE A ( ID INT PRIMARY KEY, SOME_VALUE_FROM_A INT) CREATE TABLE B ( A_ID INT NOT NULL, SOME_VALUE_FROM_B INT)
Table A contains to rows:
id | some_value_from_a ----+------------------- 1 | 1000 2 | 1000
Table B cointains a refenrence to the second row in B
a_id | some_value_from_b ------+------------------- 2 | 2000
Ok, what I want is to query the ABInterface and get two objects,
one instance of A and one of B (because id=2 and a_id=2) but what I get is one
instance of A (OK thats right), but two instaces of B. And the b instances
cointains no value for the some_value_from_a field. A query have following result:
[...]
Query q = QueryFactory.newQuery(ABInterface.class, c);
Iterator iter = broker.getCollectionByQuery(q).iterator();
while (iter.hasNext()) {
ABInterface element = (ABInterface) iter.next();
System.out.println(element.toString());
}[...]
class test.B id:0 a_value:0 b_value:2000 class test.A id:1 a_value:1000 class test.B id:0 a_value:0 b_value:2000
What I want is: class test.A id:1 a_value:1000 class test.B id:2 a_value:1000 b_value:2000
Could anyone tell what I do wrong or is it possible what want to do? ;-)
Thank you for help
Bj�rn Voigt
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
