|
I found a problem while trying to make a OQL query
using a non-primary key in the where statement. For example, in the Castor JDO
example, I create a query to find the computer whose "cpu" is "Pentium", so I
add the following cde right before marshall coding:
db.begin();
file://test search from the computer using cpu property System.out.println("Now search the cpu using Pentium"); computerOql = db.getOQLQuery( "SELECT c FROM myapp.Computer c WHERE cpu = $1" ); computerOql.bind( "Pentium" ); results = computerOql.execute(); while ( results.hasMore() ) { computer = (Computer) results.next(); writer.println( "Display existing computer: " + computer ); } db.commit();
Marshaller marshaller;
.....
It didn't print anything! The SQL query printed out
on screen is:
[test] SELECT
"COMPUTER"."ID","PROD"."NAME","PROD"."PRICE","PROD"."GROUP_ID","PR
OD_DETAIL"."ID","COMPUTER"."CPU" FROM "PROD","COMPUTER","PROD_DETAIL" WHERE "COM PUTER"."ID"="PROD"."ID" AND "COMPUTER"."ID"="PROD_DETAIL"."PROD_ID"(+) AND ("COM PUTER"."CPU" = ?) It did return a record when I run it against the
database.
When I run it using "where id=?", it will return a
record, why it don't work for query on non-primary key?
Thanks a lot,
John |
