This problems has occurred again.  It seems the fault occurs for any query of the form:

SELECT c from ClassName c WHERE c.d.e=$1



I've found a 'hack' to fix this:

In org.exolab.castor.jdo.oql.ParseTreeWalker:

Line 941 changed from:
          tableAlias = tableAlias.replace('.', '_') + "_" + index;
to:
          tableAlias = tableAlias.replace('.', '_');


This stops castor from 'aliasing' the name of the 'd' table, and makes this form of 
Queury generate valid SQL, but I imagine it will create other problems.

Can anyone direct me to a better solution?  Or, if any has successfully run queries of 
this form, can they let me know and I will take another look at our mapping 
configuration.

Thanks,
Paul Tetley



-----Original Message-----
From: Tetley, Paul 
Sent: Tuesday, June 17, 2003 5:52 PM
To: [EMAIL PROTECTED]
Subject: [castor-dev] OQL compiling into bad SQL (_0 appended to table
name)


Hello, - have scoured the website, FAQ, Google with no luck...

I'm running 0.9.5

In our business object model:  Lead has a Customer which has a KTPNumber.

To find a Lead by KTPNumber, I wrote the following OQL:  "SELECT c FROM Lead c WHERE 
c.customer.KTPNumber = $1"

Castor successfully generates SQL from this, but the SQL causes an SQLException in our 
database (HSQL).

The SQL:

SELECT 
a4.OBJECTID,a4.LASTMODIFIEDDATE,a4.LASTMODIFIEDUSER,a4.CREATEDDATE,a4.CREATEDUSER,a4.CUSTOMER_OBJECTID,a4.SOURCE_LOOKUP_LEAD_OBJECTID,a4.BRANCH_LOOKUP_OBJECTID,a4.COMMENT,a4.EMPLOYEENAME,a4.EMPLOYEEID,STATUS_HISTORY.OBJECTID,ALLOCATION_HISTORY.OBJECTID,APPOINTMENT.OBJECTID,PRODUCT_SALE.OBJECTID
FROM LEAD a1 LEFT OUTER JOIN STATUS_HISTORY ON (a1.OBJECTID=STATUS_HISTORY.OBJECTID),
LEAD a2 LEFT OUTER JOIN ALLOCATION_HISTORY ON 
(a2.OBJECTID=ALLOCATION_HISTORY.OBJECTID),
LEAD a3 LEFT OUTER JOIN APPOINTMENT ON (a3.OBJECTID=APPOINTMENT.OBJECTID),
LEAD a4 LEFT OUTER JOIN PRODUCT_SALE ON (a4.OBJECTID=PRODUCT_SALE.OBJECTID), CUSTOMER 
WHERE 
a4.CUSTOMER_OBJECTID=CUSTOMER_0.OBJECTID AND a4.OBJECTID=a3.OBJECTID AND 
a4.OBJECTID=a2.OBJECTID AND a4.OBJECTID=a1.OBJECTID AND CUSTOMER_0.KTPNUMBER = 123

The problem is in the WHERE clause.

For some reason Castor is appending _0 to the Customer table name, which of course, 
makes the SQL invalid. (CUSTOMER_0.OBJECTID does not exist)

Is this a bug, or should I be formulating my query differently?  I can't find any 
examples of 'a.b.c' query's on the web site - they all stop at 'a.b'.

TIA
Paul Tetley

----------------------------------------------------------- 
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
        unsubscribe castor-dev

----------------------------------------------------------- 
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
        unsubscribe castor-dev

Reply via email to