openjpa-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Aviram Segal (Created) (JIRA)" <>
Subject [jira] [Created] (OPENJPA-2149) Criteria.function adds wrong casts to parameters making it unsuable
Date Mon, 05 Mar 2012 07:51:04 GMT
Criteria.function adds wrong casts to parameters making it unsuable

                 Key: OPENJPA-2149
             Project: OpenJPA
          Issue Type: Bug
          Components: criteria, kernel
    Affects Versions: 2.1.1, 2.0.1, 2.0.2
         Environment: Standalone 2.0.0 and 2.0.1 downloaded from openjpa website, and on WebSphere
7 JPA2 feature pack (contains OpenJPA 2.0.2)
            Reporter: Aviram Segal
            Priority: Critical

Criteria.function will generate an SQL with only the last parameter casted and to the wrong
		Expression<String> stPointFunc = cb.function(
		Expression<Double> distanceFunc = cb.function(
				usersLocations.get("location"));, cb.literal(50.0)));

Will generate the following SQL:
(db2gse.st_distance(db2gse.st_point(?, ?, CAST(? AS DOUBLE)), t0.LOCATION) < ?)
Notice the 3rd parameter is an Integer and its being cast as Double.
The problem is in org.apache.openjpa.jdbc.kernel.exps.DatastoreFunction#appendTo

Line 54:  args.appendTo(sel, ctx, state, sql, 0);
Will append 3 ? to the sql buffer "(db2gse.st_distance(db2gse.st_point(?, ?, ?"
Then the loop in line 56-58
            for (int i = 1; i < vals.length; i++) {
                sql.addCastForParam(getOperator(), vals[i]);

Starts with 1 (second parameter and not the first one), whil sql.addCastForParam only works
for the last ? in the sql buffer, meaning the cast for the param at index 1 is added to the
last ? and the method will not do anything else.

This issue leaves Criteria.function useless to me, I tried extending my DBDictionary to remove
all the cast as a work around but the function became ambiguous.

Thanks in advance.

This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators:!default.jspa
For more information on JIRA, see:


View raw message