[ 
https://issues.apache.org/jira/browse/OPENJPA-2729?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18154010#comment-18154010
 ] 

ASF subversion and git services commented on OPENJPA-2729:
----------------------------------------------------------

Commit 8f38dd2df3ef9d0124f367bd98ef7aa925565a22 in openjpa's branch 
refs/heads/OPENJPA-3106 from Richard Zowalla
[ https://gitbox.apache.org/repos/asf?p=openjpa.git;h=8f38dd2df ]

[OPENJPA-2729] Use the column of the path for LOWER and UPPER of a collection 
element (#331)

* [OPENJPA-2729] Use the column of the path for LOWER and UPPER of a collection 
element

LOWER and UPPER took the column for the cast function from the columns of
the field mapping of the path. For an element collection of strings, or the
key or value of an element collection map, the field has no columns of its
own, the column is on the collection table, so building the SQL failed with
an ArrayIndexOutOfBoundsException. Take the column from the path itself,
which returns the element, key or value column, and use the cast function
without a column when the path has none.

* [OPENJPA-2729] Use pattern matching for the path operand of StringFunction

> problem with ToUpperCase and ToLowerCase
> ----------------------------------------
>
>                 Key: OPENJPA-2729
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-2729
>             Project: OpenJPA
>          Issue Type: Bug
>          Components: query
>    Affects Versions: 2.4.2
>         Environment: MySQL
>            Reporter: Patrice DUROUX
>            Assignee: Richard Zowalla
>            Priority: Major
>             Fix For: 4.3.0
>
>         Attachments: openjpa-test.zip
>
>
> Hi,
> An exception is thrown in the following method (here the one of ToLowerCase):
> when the getValue() is a PCPath and ((PCPath) 
> getValue()).getFieldMapping(state).getColumns()[0])
> throws:
> {{java.lang.ArrayIndexOutOfBoundsException: 0}}{{ 
> org.apache.openjpa.jdbc.kernel.exps.ToLowerCase.appendTo(ToLowerCase.java:47) 
> org.apache.openjpa.jdbc.kernel.exps.MatchesExpression.appendTo(MatchesExpression.java:97)
>  
> org.apache.openjpa.jdbc.kernel.exps.AndExpression.appendTo(AndExpression.java:59)}}
>  
>  
> {{    public void appendTo(Select sel, ExpContext ctx, ExpState state, }}
> {{        SQLBuffer buf, int index) {}}
> {{        DBDictionary dict = ctx.store.getDBDictionary();}}
> {{        String func = dict.toLowerCaseFunction;}}
> {{        dict.assertSupport(func != null, "ToLowerCaseFunction");}}
> {{        if (getValue() instanceof PCPath) {}}
> {{            func = dict.getCastFunction(getValue(), func, ((PCPath) 
> getValue()).getFieldMapping(state).getColumns()[0]);}}
> {{        } else {}}
> {{            func = dict.getCastFunction(getValue(), func);}}
> {{        }}}
> {{        int idx = func.indexOf("\{0}");}}
> {{        buf.append(func.substring(0, idx));}}
> {{        getValue().appendTo(sel, ctx, state, buf, index);}}
> {{        buf.append(func.substring(idx + 3));}}
> {{    }}}
> The part of code that generate the exception is:
>         Path<String> authorPath = from.join("references").join("authors");
>         predicateList.add(cb.like(cb.lower(authorPath), cb.literal('%' + 
> value + '%')));
> If I change this code to use another string function like trim(), it works 
> (ie. the SQL query is correctly generated).
>  
> Regards,
> Patrice
> ps: remark that the only uses of DBDictionary.getCastFunction(Val val, String 
> func, Column col) are for those classes.



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to