Hello,

I am using the ODMG API.
i don't know whether this behaviour is to be expected:

I am mapping a child class to it's parent class via multiple joined tables.
When I retrive objects of the parent class from the Database, some of the
returned objects should be members of a child class.
But if i ask  for the objects of the parent class, I only get them as
instances of the parent class.
In the spy.log - File I can see that only parent objects are retrieved.

What can I do to get the "real" objects?




The repository:
<class-descriptor class="test.Point" table="point">
      <field-descriptor id="1"      name="id"         column="id"
jdbc-type="INTEGER"
                        primarykey="true"       autoincrement="true"
access="anonymous"/>
      <field-descriptor id="2"      name="region"           column="region"
      jdbc-type="VARCHAR"/>
</class-descriptor>
<class-descriptor class="test.NamedPoint" table="namedpoint">
      <field-descriptor id="1"      name="id"         column="id"
jdbc-type="INTEGER"
                        primarykey="true"       autoincrement="true"
access="anonymous"/>
      <field-descriptor id="2"      name="name"             column="name"
jdbc-type="VARCHAR"/>
      <reference-descriptor name="super" class-ref="test.Point">
<foreignkey field-ref="id" /> </reference-descriptor>
</class-descriptor>

the table definitions:
CREATE TABLE point (id INT PRIMARY KEY, region VARCHAR (20)) ;
CREATE TABLE namedpoint (id INT PRIMARY KEY,name VARCHAR (20)) ;

the main - Method (Class definitions are as expected from the repository):
      public static void main(String[] args) {
            // Open Database
            Implementation theOdmg = OJB.getInstance();
            Database theDb = theOdmg.newDatabase();
            try {
                  theDb.open("default", Database.OPEN_READ_WRITE);
            } catch (ODMGException ex) {
                  ex.printStackTrace();
            }

            //Create a NamedPoint
            Transaction tx = theOdmg.newTransaction();
            tx.begin();
            NamedPoint np = new NamedPoint();
            np.setRegion("region");
            np.setName("test");
            tx.lock(np, Transaction.WRITE);
            tx.commit();

            //get Point
            tx = theOdmg.newTransaction();
            tx.begin();
            OQLQuery query = theOdmg.newOQLQuery();
            DList pointList = null;
            try {
                  String queryString =
                        "select all from " + Point.class.getName() + "
where region =\"region\"";
                  query.create(queryString);
                  pointList = (DList) query.execute();

                  java.util.Iterator iter = pointList.iterator();
                  while (iter.hasNext()) {
                        Point point = (Point) iter.next();
                        if (point instanceof NamedPoint) {
                              System.out.println("Named Point!");
                        } else {
                              System.out.println("No Named Point!");
                        }
                  }
            } catch (QueryInvalidException ex) {
                  ex.printStackTrace();
            } catch (QueryException ex) {
                  ex.printStackTrace();
            }
      }

the text on the Screen:
No Named Point!

thanks,
Birgitta

Reply via email to