First of all please excuse me for my bad english!!
I know that ilike() must do case-insensitive comparing...so upper or lower is not important...
Code:
public class IlikeExpression implements Criterion
/*A case-insensitive "like"
*
* @author Gavin King
*/
but if i would like to choose the behaviour??
Hibernate version: 3.2.0 rc4
Name and version of the database you are using:oracle 9
The generated SQL (show_sql=true):Code:
...
where lower(this_.NAME) like ? and this_.ID>=? ) where rownum <= ?
...
This code is correct. It is generated using this like expression:
Code:
Expression.ilike(name, value)
I would like instead somthing like this for compatibility problems...
Code:
...
this_ where upper(this_.NAME) like ? and this_.ID>=? ) where rownum <= ?
...
And obvsiously i also would like that HIbernate could use .toUpperCase() instead of .toLowerCase() on the String identified by the ?
I tried with this solution:
Code:
Restrictions.sqlRestriction("upper({alias}." + name + ") like upper(?)", value, Hibernate.STRING);
It give me the desired behaviour... but it is not optimized...because hibernate still make an operaion of toLowerCase on ?, and only after the db uses the upper() operator. And this is useless.
So i modifed the hibernate source code, implementing a parametric method:
Code:
public static Criterion ilike(String propertyName, Object value, int CONVERT_MODE) {
return new IlikeExpression(propertyName, value, CONVERT_MODE);
}
And obviously i also modified the called method to implement the needed behaviour... in that way:
Code:
protected IlikeExpression(String propertyName, Object value,
int CONVERT_MODE) {
this.propertyName = propertyName;
this.value = value;
this.selectedCM = CONVERT_MODE;
}
@Deprecated
protected IlikeExpression(String propertyName, Object value) {
this.propertyName = propertyName;
this.value = value;
this.selectedCM = CONVERT_MODE_LOWER_CASE;
}
protected IlikeExpression(String propertyName, String value,
MatchMode matchMode, int CONVERT_MODE) {
this(propertyName, matchMode.toMatchString(value), CONVERT_MODE);
}
@Deprecated
protected IlikeExpression(String propertyName, String value,
MatchMode matchMode) {
this(propertyName, matchMode.toMatchString(value),
CONVERT_MODE_LOWER_CASE);
}
etc. etc.
In that way the method ensure the retrocompatibility with previous implementation.
Do you think this could be interesting for someone?
Is this the correct approach to the problem or i made some basic error??