Tabler per hierarchy and custom objConcreteClass field

martindb <[email protected]> Wed, 23 Jul 2008 08:50:45 -0700 (PDT)
Newsgroups gmane.comp.jakarta.ojb.user
Message-ID <[email protected]>
Hi,
I'm facing this problem:  When I do a search over a base class, it
instantiates the correct subclass type, but doesn't retrieve all the
attributes from the subclass, only those that belong to the base class.

These classes and mappings are a simplified version of the original ones,
but respect the main structure.

* I have these classes:

public class BaseClass implements Serializable, Comparable
{
=09private int=09=09id1;
=09private String=09=09type;
=09private int=09=09id2;
=20
        //some more attributes
        private int             at1;        =20

}

public class SubClass extends BaseClass {
        private int=09=09at2;
}

* these custom RowReader (implemented as documentation says):

public class ClassRowReader extends RowReaderDefaultImpl {

=09public OUBesoinRowReader(ClassDescriptor a_classDescriptor) {
=09=09super(a_classDescriptor);
=09}

=09protected ClassDescriptor selectClassDescriptor(Map row) throws
PersistenceBrokerException {
=09    //Determine type
=09    String classType =3D (String) row.get("type");
=09    if("subclass".equals(classType)){
=09        return
getClassDescriptor().getRepository().getDescriptorFor(SubClass.class);
=09    }

             //future subclasses check=09   =20
=09   =20
=09    //Throw exception
        throw new Exception("Can't create an object of type '" + classType =
+
"'");

=09}

}


* these mappings:

<class-descriptor class=3D"BaseClass" table=3D"TableA"=20
=09row-reader=3D"ClassRowReader">
=09
=09<extent-class class-ref=3D"SubClass" />
=09///future subclasses
=09<field-descriptor name=3D"id1" column=3D"COL1" jdbc-type=3D"INTEGER"
primarykey=3D"true" />
=09<field-descriptor name=3D"id2" column=3D"COL2" jdbc-type=3D"INTEGER"
primarykey=3D"true" />
=09<field-descriptor name=3D"type" column=3D"COL3" jdbc-type=3D"VARCHAR"
primarykey=3D"true" />
=09<field-descriptor name=3D"at1" column=3D"COL4" jdbc-type=3D"VARCHAR"/>

</class-descriptor>

<class-descriptor class=3D"SubClass" table=3D"TableA" >
=09<field-descriptor name=3D"id1" column=3D"COL1" jdbc-type=3D"INTEGER"
primarykey=3D"true" />
=09<field-descriptor name=3D"id2" column=3D"COL2" jdbc-type=3D"INTEGER"
primarykey=3D"true" />
=09<field-descriptor name=3D"type" column=3D"COL3" jdbc-type=3D"VARCHAR"
primarykey=3D"true" />
=09<field-descriptor name=3D"at1" column=3D"COL4" jdbc-type=3D"INTEGER"/>
=09<field-descriptor name=3D"at2" column=3D"COL5" jdbc-type=3D"INTEGER"/>
</class-descriptor>

* ojb-version: 1.0.4

* Query:

=09=09Criteria l_criteria =3D new Criteria();
=09=09l_criteria.addEqualTo("id1", new Integer(id));
=09=09l_criteria.addEqualTo("type", "Subclass");
=09=09
=09=09QueryByCriteria l_query =3D new QueryByCriteria(BaseClass.class,
l_criteria);
                //get the broker...

                Collection objects =3D l_broker.getCollectionByQuery(l_quer=
y);


* Logs:  I activated the sql log, and the select generated did bring the
SubClass specific attributes, but for some reason they were not passed to
the rowreader.

Thanks,
Mart=C3=ADn.
--=20
View this message in context: http://www.nabble.com/Tabler-per-hierarchy-an=
d-custom-objConcreteClass-field-tp18613951p18613951.html
Sent from the Apache DB - ObjectRelationalBridge Users mailing list archive=
 at Nabble.com.