Quantcast

Tabler per hierarchy and custom objConcreteClass field

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Tabler per hierarchy and custom objConcreteClass field

martindb
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
{
        private int id1;
        private String type;
        private int id2;
 
        //some more attributes
        private int             at1;        

}

public class SubClass extends BaseClass {
        private int at2;
}

* these custom RowReader (implemented as documentation says):

public class ClassRowReader extends RowReaderDefaultImpl {

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

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

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

        }

}


* these mappings:

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

</class-descriptor>

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

* ojb-version: 1.0.4

* Query:

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

                Collection objects = l_broker.getCollectionByQuery(l_query);


* 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ín.
Loading...