[prev in list] [next in list] [prev in thread] [next in thread]
List: ojb-user
Subject: Re: Problem with Mapping Inheritance Hierarchies
From: Björn_Voigt <bvoigt () hs-harz ! de>
Date: 2004-03-26 12:43:14
Message-ID: c418b4$q9k$1 () sea ! gmane ! org
[Download RAW message or body]
Hello again,
I have still problems with mapping inheritance hierarchies.
I solved my first problem with nonfilled extend fields in the
subclass, but I still recieve two instances of one row.
My tables contains the following rows
select * from a;
id | some_value_from_a
----+-------------------
1 | 1000
2 | 1000
select * from b;
id | a_id | some_value_from_b
----+------+-------------------
1 | 2 | 2000
A query has the this result ( there are two instances of B for one Row)
class test.B id:2 a_value:1000 b_value:2000
class test.B id:2 a_value:1000 b_value:2000
class test.A id:2 a_value:1000
Björn Voigt schrieb:
> Hello OJB'lers,
>
> 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: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic