Hallo erstmal,
i've tried the following with Castor 1.0.4 and 1.1 on an Oracle 10g database 
and in both cases ran into the same problem.

my mapping:
 
 <class name="de.hbo.test.castor.ClassA" identity="id">
   
 <map-to table="CLASSA"/>
    
   <field name="id" type="integer">
     <sql name="id" type="integer"/>
   </field>
 
   <field name="children" type="de.hbo.test.castor.ClassB" 
collection="arraylist">
     <sql many-key="parentid"/>
   </field>
 
 </class>
 

 <class name="de.hbo.test.castor.ClassB" identity="id">
   
   <map-to table="CLASSB"/>
     
   <field name="id" type="integer">
     <sql name="id" type="integer"/>
   </field>
 
   <field name="parent" type="de.hbo.test.castor.ClassA">
     <sql name="parentid"/>
   </field>
 
 </class>
 

 <class name="de.hbo.test.castor.ClassC1" identity="id" 
extends="de.hbo.test.castor.ClassB">
   
   <map-to table="CLASSC1"/>
     
   <field name="id" type="integer" >
     <sql name="id" type="integer"/>
   </field>

 </class>


 <class name="de.hbo.test.castor.ClassC2" identity="id" 
extends="de.hbo.test.castor.ClassB">
   
   <map-to table="CLASSC2"/>
     
   <field name="id" type="integer" >
     <sql name="id" type="integer"/>
   </field>

 </class>



I've the following table-entries

CLASSA:
        ID
----------
         1
         2


CLASSB:

        ID   PARENTID
---------- ----------
         1          1
         2          2
         3          1


CLASSC1:

        ID
----------
         1
         3


CLASSC2:

        ID
----------
         2


and when trying to retrieve all ClassA-objects by running


 db.begin();
  
 query = db.getOQLQuery("select a from de.hbo.test.castor.ClassA a");
 
 result = query.execute();
  
 List erg = new ArrayList();
 while (result.hasMore()) erg.add(result.next());
  
 db.commit();


I got a  [ClassA(id=1), ClassA(id=2), ClassA(id=1)] - list (with the two 
ClassA(id=1)-objects each having just a C1-child(id=1))

instead of a [ClassA(id=1), ClassA(id=2)] - list, which I thought I would get.

Do I do something wrong or is it a bug?




There are two more things I found out, that maybe help you to help me.

1. 
When I change the database-entries as follows (the first two children belong to 
the first ClassA-Object(id = 1) and the third to the second 

ClassA-object(id = 2))


CLASSA:
        ID
----------
         1
         2


CLASSB:

        ID   PARENTID
---------- ----------
         1          1
         2          1
         3          2


CLASSC1:

        ID
----------
         1
         3


CLASSC2:

        ID
----------
         2

I get what I'm expecting.


2.
When I change the source-code as follows (and leave the database in its 
original state)

 ...
 
 //query = db.getOQLQuery("select a from de.hbo.test.castor.ClassA a");
 
 query = db.getOQLQuery("select a from de.hbo.test.castor.ClassA a where id = 
$1");
 query.bind(new Integer(1));
 
 ...

I get one ClassA-object(id = 1) with one C1- and one C2-child (as expected).




Thanks in advance, 
Hubert.

Reply via email to