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 RESULT
===========
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]
false,cascade_store=object,cascade_delete=none,is_lazy=false,class_of_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]