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