Hi,
Thanks Wallace I have followed your advice, the descriptor is now more
readable but that doesn't solve the problem.
I run the following tests:
- storing one instance of B: test OK
- storing one instance A with a collection of A elements (non
recursive): test OK
- storing one instance B with a collection of A elements (non
recursive): test OK
- storing one instance A with a collection of B elements (non
recursive): test KO
The error message is always:
org.apache.ojb.broker.OJBRuntimeException: Incorrect or not found field
reference name 'parentId' in descriptor
<mailto:[EMAIL PROTECTED]
de_retrieve=false,cascade_store=object,cascade_delete=none,is_lazy=false
,class_of_Items=>
[EMAIL PROTECTED]
eve=false,cascade_store=object,cascade_delete=none,is_lazy=false,class_o
f_Items=<null>] for class-descriptor 'ojb.test.B'
With the first test I check the Oid is managed correctly. I use the
SequenceManagerNextValImpl class to generate an unique Id on each
table. The T_B.oid column is the primary key for T_B and also a foreign
key for T_A, for one instance of B, T_B.oid and T_A.oid have the same
value, it's OK.
So I don't understand why outside the collection B is correctly store
(that means the id is unique all along the extent hierarchy) and not
inside the collection.
It seems B element in a collection don't use the "super" keyword present
in the reference descriptor to A.
Is a problem with the
"org.apache.ojb.broker.metadata.CollectionDescriptor" which does not
read the descriptor of the superclass?
Is it a known limitation in OJB?
Thanks
Gildas
----- Original Message -----
From: "Gelhar, Wallace Joseph" < <mailto:[EMAIL PROTECTED]>
[EMAIL PROTECTED]>
To: "OJB Users List" < <mailto:[EMAIL PROTECTED]>
[EMAIL PROTECTED]>
Sent: Friday, May 14, 2004 7:36 PM
Subject: RE: polymorphic and recursive collection
> I'll take a stab at this.
>
> First, a couple of things you have *may* work, but seem confusing.
>
> First of all, the children INTEGER field on the table T_A is a FK to
the
> parent object, so I would recommend naming it as such. This will also
> eliminate a possible problem with the collection and the FK being
named
> the same "children".
>
> <class-descriptor class="ojb.test.A" table="T_A"
> isolation-level="read-uncommitted" accept-locks="true" refresh="true"
>
> <field-descriptor name="oid" column="oid" jdbc-type="INTEGER"
> primarykey="true" autoincrement="true"/>
> <field-descriptor name="attA" column="attA"
> jdbc-type="VARCHAR"/>
> <field-descriptor name="parentID" column="parentID"
> jdbc-type="INTEGER" access="anonymous" />
> <!-- lien sur les fils -->
> <collection-descriptor name="children" auto-update="true">
> <inverse-foreignkey field-ref="parentID"/>
> </collection-descriptor>
> </class-descriptor>
>
> The second part about the polymorphic is possibly due to the sequence
> implemenation you use. The oid *must* be unique across all extents.
If
> you use SequenceManagerHighLowImpl, then either set it as a global
> unique identifiers or set a sequence-name="name_for_extent_hierarchy"
in
> each PK for each class in the extent hierarchy. Without this, if you
> have two objects (A oid=3) and (B oid=3), ojb has no way to know that
> the object with oid 3 is a A or B object, so it assumes the senior
most
> object A.
>
> Hope this helps.
>
> -----Original Message-----
> From: LE-QUERE Gildas - REN [mailto:[EMAIL PROTECTED]
> Sent: Friday, May 14, 2004 2:21 AM
> To: <mailto:[EMAIL PROTECTED]> [EMAIL PROTECTED]
> Subject: polymorphic and recursive collection
>
>
> Hi All,
>
> I want to make persistent a polymorphic and recursive collection
(custom
> implementation).
>
> The collection elements are instances of the A class and the B class.
B
> extents A.
>
> The A class contains this collection.
>
> UML model
>
> _________________
> * | children | type 1:N relationship
> -----------\/------ |
> | A | |
> |------------------| |
> | oid: int | |
> | attA: String | -------
> |__________________|
> /\
> |
> -------------------
> | B |
> |------------------|
> | attB: String |
> |__________________|
>
> Database schema (tested with Oracle)
>
> create table T_A (
>
> attA VARCHAR ( 48 ) NULL,
>
> children INTEGER NULL,
>
> oid INTEGER NOT NULL,
>
> constraint PK_T_A PRIMARY KEY (oid)
>
> )
>
> create table T_B (
>
> attB VARCHAR ( 48 ) NULL,
>
> oid INTEGER NOT NULL,
>
> constraint PK_T_B PRIMARY KEY (oid)
>
> )
>
> -- 1:N relationship
>
> alter table T_A add constraint FK_T_children foreign key (children)
> references T_A (oid)
>
> /
>
> -- inheritance
>
> alter table T_B add constraint FK_T_AB foreign key (oid) references
T_A
> (oid)
>
> /
>
>
> Mapping in the repository.xml
>
> <class-descriptor class="ojb.test.A" table="T_A"
> isolation-level="read-uncommitted" accept-locks="true" refresh="true"
>
>
> <field-descriptor name="oid" column="oid" jdbc-type="INTEGER"
> primarykey="true" autoincrement="true"/>
>
> <field-descriptor name="attA" column="attA"
> jdbc-type="VARCHAR"/>
>
> <field-descriptor name="children" column="children"
> jdbc-type="INTEGER" access="anonymous" />
>
> <!-- lien sur les fils -->
>
> <collection-descriptor name="children" auto-update="true">
>
> <inverse-foreignkey field-ref="children"/>
>
> </collection-descriptor>
>
> </class-descriptor>
>
> <class-descriptor class="ojb.test.B" table="T_B"
> isolation-level="read-uncommitted" accept-locks="true" refresh="true">
>
> <field-descriptor name="oid" column="oid" jdbc-type="INTEGER"
> primarykey="true" autoincrement="true" />
>
> <field-descriptor name="attB" column="attB"
> jdbc-type="VARCHAR"/>
>
> <!-- inheritance A - B -->
>
> <reference-descriptor name="super" class-ref="ojb.test.A"
> auto-retrieve="true" auto-delete="true" auto-update="true">
>
> <foreignkey field-ref="oid"/>
>
> </reference-descriptor>
>
> </class-descriptor>
>
> Java code
>
> public class A {
>
> private int oid;
>
> private String attA = null;
>
> private MyCollection children = null;
>
> }
>
> public class B extends A {
>
> private String attB = null;
>
> }
>
> public class MyCollection implements Collection {
>
> private Vector v = null;
>
> }
>
> Test results
>
> If the collection contains A element only that works fine. If the
> collection contains B elements OJB doesn't see that B is a A subclass
> and throws an Exception because it doesn't find the chidren foreign
key.
> I have the following error message:
>
________________________________________________________________________
>
> org.apache.ojb.broker.OJBRuntimeException: Incorrect or not found
field
> reference name 'children' in descriptor
>
<mailto:[EMAIL PROTECTED]
de_retri>
[EMAIL PROTECTED]
>
eve=false,cascade_store=object,cascade_delete=none,is_lazy=false,class_o
> f_Items=<null>] for class-descriptor 'ojb.test.B'
>
>
________________________________________________________________________
>
> Please can you help me.
>
> Thanks
>
> Gildas
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
[EMAIL PROTECTED]
> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>
[EMAIL PROTECTED]