Hi all,

On our project, we found (and fix) a problem related to self-refered table
when the PK is a multi-column PK.

Were using torque-3.0-b2, ( btw, is there an plan for tagging beta 3, I'd
like to get my project DataSource/Jndi compliant).

Here's a minimalist schema to reproduce it :

    <database>
        <table name="TEST_TABLE">
            <column name="COL1" primaryKey="true" required="true"
type="DECIMAL"/>
            <column name="COL2" primaryKey="true" required="true"
type="DECIMAL"/>
            
            <column name="PARENT_COL1" required="true" type="DECIMAL"/>
            <column name="PARENT_COL2" required="true" type="DECIMAL"/>
            
            <foreign-key foreignTable="TEST_TABLE">
                <reference foreign="COL1" local="PARENT_COL1"/>
                <reference foreign="COL2" local="PARENT_COL2"/>
            </foreign-key>
        </table>
        </database>

The generated Object TestTable.java won't compile, the generated methods
getTestRelatedBy**** are broken :
On one side, the Object.vm creates a reference to the pointed TestTable
object with the name :
        aTestTableRelatedByParentCol1Col2

But on an other portion of the velocity code, it is reffered as 
        aTestTableRelatedByParentCol1

The code works for a Single column PK but not for my test Case :



compile:
    [javac] Compiling 1 source file to D:\projets\sicol\war\WEB-INF\classes
    [javac] D:/projets/sicol/src/sicol/om/BaseTestTable.java:176:13:176:13:
Error: No field named "aTestTableRelatedByParentCol1" was found in type
"sicol/om/BaseTestTable". However, there is an accessible field
"aTestTableRelatedByParentCol1ParentCol2" whose name closely matches the
name "aTestTableRelatedByParentCol1".
    [javac] D:/projets/sicol/src/sicol/om/BaseTestTable.java:176:71:176:71:
Error: "aTestTableRelatedByParentCol1" is either a misplaced package name or
a non-existent entity.
    [javac] D:/projets/sicol/src/sicol/om/BaseTestTable.java:178:13:178:13:
Error: No field named "aTestTableRelatedByParentCol1" was found in type
"sicol/om/BaseTestTable". However, there is an accessible field
"aTestTableRelatedByParentCol1ParentCol2" whose name closely matches the
name "aTestTableRelatedByParentCol1".
    [javac] D:/projets/sicol/src/sicol/om/BaseTestTable.java:228:13:228:13:
Error: No field named "aTestTableRelatedByParentCol2" was found in type
"sicol/om/BaseTestTable". However, there is an accessible field
"aTestTableRelatedByParentCol1ParentCol2" whose name closely matches the
name "aTestTableRelatedByParentCol2".
    [javac] D:/projets/sicol/src/sicol/om/BaseTestTable.java:228:71:228:71:
Error: "aTestTableRelatedByParentCol2" is either a misplaced package name or
a non-existent entity.
    [javac] D:/projets/sicol/src/sicol/om/BaseTestTable.java:230:13:230:13:
Error: No field named "aTestTableRelatedByParentCol2" was found in type
"sicol/om/BaseTestTable". However, there is an accessible field
"aTestTableRelatedByParentCol1ParentCol2" whose name closely matches the
name "aTestTableRelatedByParentCol2".


And here is the patch for Object.vm r 1.24 that correct this problem :

***
cvs diff -N -u "Object.vm"
  Index: Object.vm
  ===================================================================
  RCS file:
/home/cvspublic/jakarta-turbine-torque/src/templates/om/Object.vm,v
  retrieving revision 1.24
  diff -u -r1.24 Object.vm
  --- Object.vm 14 Mar 2002 12:38:49 -0000      1.24
  +++ Object.vm 7 Jun 2002 14:19:37 -0000
  @@ -174,7 +174,15 @@
               #if ( !($tblFK.Name.equals($table.Name)) )
                 #set ( $colFK = $tblFK.getColumn($fkColName) )
                 #if ($colFK.isMultipleFK())
  -                #set ( $collName =
"coll${tblFK.JavaName}sRelatedBy$colFK.JavaName" )
  +                #set ( $relCol = "" )
  +                #foreach ($columnName in $col.foreignKey.LocalColumns)  
  +                    #set ( $column = $table.getColumn($columnName) )
  +                    #set ( $relCol = "$relCol$column.JavaName" )
  +                #end
  +               #if ($relCol != "")
  +                   #set ( $relCol = "RelatedBy$relCol" )
  +               #end
  +               #set ( $varName = "a${tblFK.JavaName}$relCol" )
                 #else
                   #set ( $collName = "coll${tblFK.JavaName}s" )
                 #end



Could someone try it and commit it ?
Thanks,
Alexis.

-------------------
M. Alexis HAUMONT
SMILE 
93, rue Amp�re
75 017 PARIS - FRANCE

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to