You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@turbine.apache.org by Steve <tu...@knology.net> on 2002/01/29 05:18:06 UTC

Problems getting a schema to compile using FKs (long!)

Hi all:

I could use a little (lot of!) help with this.  I've been attempting to
generate Peers for a "legacy" Oracle database (read "legacy" as changes to
the schema are problematic) and the Torque-generated classses won't compile.
Most of my problems seem to stem from having combination PKs that exist in
multiple relationships, which is perfectly valid, but Torque doesn't seem to
like it.

Example:  Consider the following very simple schema of 3 entities: a Company
which may contain many Offices and many Employees.

<database>
  <table name="COMPANY">
    <column name="CODE" required="true" primaryKey="true" size="15"
type="VARCHAR"/>
  </table>
  <table name="OFFICE">
    <column name="COMPANY_CODE" required="true" primaryKey="true" size="15"
type="VARCHAR"/>
    <column name="ID" required="true" primaryKey="true" size="5"
type="VARCHAR"/>
    <foreign-key foreignTable="COMPANY">
      <reference local="COMPANY_CODE" foreign="CODE"/>
    </foreign-key>
  </table>
  <table name="EMPLOYEE">
    <column name="ID" required="true" primaryKey="true" size="9"
type="VARCHAR"/>
    <column name="COMPANY_CODE" required="true" size="15" type="VARCHAR"/>
    <column name="OFFICE_ID" size="5" type="VARCHAR"/>
    <foreign-key foreignTable="OFFICE">
      <reference local="COMPANY_CODE" foreign="COMPANY_CODE"/>
      <reference local="OFFICE_ID" foreign="ID"/>
    </foreign-key>
    <foreign-key foreignTable="COMPANY">
      <reference local="COMPANY_CODE" foreign="CODE"/>
    </foreign-key>
  </table>
</database>

But Torque has problems with the Employee entity, because its column,
company_code, exists in two FK relationships: one with Company and one with
Office.  This is a perfectly valid database design, however, if you consider
the following.  An employee's company_code is required, but his office_id is
optional; but if the office_id is entered, it should be constrained against
the values in the Office entity.

Seems reasonable right?

Here's the compile errors.  These appear in the getEmployees &
getEmployeesJoinOffice methods of BaseCompany.

    [javac] D:\torque\src\java\adom\BaseCompany.java:313: cannot resolve
symbol
    [javac] symbol  : method getOfficeId  ()
    [javac] location: class adom.BaseCompany
    [javac]                    criteria.add(EmployeePeer.COMPANY_CODE,
getOfficeId() );
    [javac]                                                            ^
    [javac] D:\torque\src\java\adom\BaseCompany.java:314: cannot resolve
symbol
    [javac] symbol  : method getOfficeId  ()
    [javac] location: class adom.BaseCompany
    [javac]                    criteria.add(EmployeePeer.OFFICE_ID,
getOfficeId() );
    [javac]                                                         ^
    [javac] D:\torque\src\java\adom\BaseCompany.java:336: cannot resolve
symbol
    [javac] symbol  : method getOfficeId  ()
    [javac] location: class adom.BaseCompany
    [javac]                    criteria.add(EmployeePeer.COMPANY_CODE,
getOfficeId() );
    [javac]                                                            ^
    [javac] D:\torque\src\java\adom\BaseCompany.java:337: cannot resolve
symbol
    [javac] symbol  : method getOfficeId  ()
    [javac] location: class adom.BaseCompany
    [javac]                    criteria.add(EmployeePeer.OFFICE_ID,
getOfficeId() );
    [javac]                                                         ^
    [javac] D:\torque\src\java\adom\BaseCompany.java:377: cannot resolve
symbol
    [javac] symbol  : method getOfficeId  ()
    [javac] location: class adom.BaseCompany
    [javac]                    criteria.add(EmployeePeer.COMPANY_CODE,
getOfficeId() );
    [javac]                                                            ^
    [javac] D:\torque\src\java\adom\BaseCompany.java:378: cannot resolve
symbol
    [javac] symbol  : method getOfficeId  ()
    [javac] location: class adom.BaseCompany
    [javac]                    criteria.add(EmployeePeer.OFFICE_ID,
getOfficeId() );
    [javac]                                                         ^
    [javac] D:\torque\src\java\adom\BaseCompany.java:390: cannot resolve
symbol
    [javac] symbol  : method getOfficeId  ()
    [javac] location: class adom.BaseCompany
    [javac]                    criteria.add(EmployeePeer.COMPANY_CODE,
getOfficeId() );
    [javac]                                                            ^
    [javac] D:\torque\src\java\adom\BaseCompany.java:391: cannot resolve
symbol
    [javac] symbol  : method getOfficeId  ()
    [javac] location: class adom.BaseCompany
    [javac]                    criteria.add(EmployeePeer.OFFICE_ID,
getOfficeId() );
    [javac]                                                         ^
    [javac] 8 errors

BUILD FAILED

Based on the error messages, it looks like an error in the Object.vm
template.  I, however, wasn't programmer enough to figure out the template's
FK logic enough to be sure anything that I "fixed" wouldn't break something
else.  Can anyone else help?

Steve


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>