You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-user@db.apache.org by Ryan Vanderwerf <ry...@kpi-consulting.net> on 2005/05/26 00:22:37 UTC

mapping classes on multiple joined tables


Hi, I'm having a problem with mapping classes on multiple joined tables on OJB
1.0.3. I am following the 'Advanced O/R' 

tutorial in the section 'Mapping Classes on Multiple Joined Tables'.

I have 2 tables, one table is a child of the other:
parent
------

<class-descriptor
             class="Company_statuses"
             table="COMPANY_STATUSES"
       > 
  <field-descriptor id="1"
     name="status_id"
     column="STATUS_ID"
     jdbc-type="INTEGER"
     primarykey="true"
     autoincrement="true"
  />
  <field-descriptor id="2"
     name="status_code"
     column="STATUS_CODE"
     jdbc-type="VARCHAR"
  />
  <field-descriptor id="3"
     name="sub_program_id"
     column="SUB_PROGRAM_ID"
     jdbc-type="INTEGER"
  />
</class-descriptor>

child
---------

<class-descriptor
             class="Company_status_trans"
             table="COMPANY_STATUS_TRANS"
       > 
  <field-descriptor id="1"
     name="company_status_trans_id"
     column="COMPANY_STATUS_TRANS_ID"
     jdbc-type="INTEGER"
     primarykey="true"
     autoincrement="true"
  />
  <field-descriptor id="2"
     name="status_id"
     column="COMPANY_STATUS_ID"
     jdbc-type="INTEGER"
  />
  <field-descriptor id="3"
     name="display_name"
     column="DISPLAY_NAME"
     jdbc-type="VARCHAR"
  />
  <field-descriptor id="4"
     name="opco_id"
     column="OPCO_ID"
     jdbc-type="INTEGER"
  />
<reference-descriptor name="super"
       class-ref="Company_statuses"
      auto-retrieve="true"
        auto-update="true"
        auto-delete="true">
     <foreignkey field-ref="status_id" />
  </reference-descriptor>
</class-descriptor>

I'm trying to do a query like it suggests, where I do a query to the child table
with 2 criteria, 1 being a column from the 

parent table and one from the child table like it says in the example:

            Criteria criteria = new Criteria();
            criteria.addEqualTo(Company_status_trans.SUB_PROGRAM_ID, new
Integer(subProgramId)); // this is in parent table
            criteria.addEqualTo("opco_id", new Integer(opCoId)); // this is in
child table
            Query query = QueryFactory.newQuery(Company_status_trans.class,
criteria);
            c = broker.getCollectionByQuery(query);

result in a SQL error, because it is trying to find the child attribute
'opco_id' in the parent table.

[5:05:03.048 PM] ERROR [CompanyManager] Error getCompanyStatuses()
org.apache.ojb.broker.PersistenceBrokerException:
org.apache.ojb.broker.Persiste
nceBrokerSQLException: SQLException during the execution of the query (for
Company_statuses): [DB]Invalid column name 

'opco_id'.

        at
org.apache.ojb.broker.core.QueryReferenceBroker.getCollectionByQuery(
Unknown Source)
        at
org.apache.ojb.broker.core.QueryReferenceBroker.getCollectionByQuery(
Unknown Source)
        at
org.apache.ojb.broker.core.PersistenceBrokerImpl.getCollectionByQuery
(Unknown Source)
        at
org.apache.ojb.broker.core.DelegatingPersistenceBroker.getCollectionB
yQuery(Unknown Source)
        at
org.apache.ojb.broker.core.DelegatingPersistenceBroker.getCollectionB
yQuery(Unknown Source)

According to the example isn't OJB supposed to figure out which table to get it
from when I specify the attribute names?

Ryan

---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org