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

Reply via email to