-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: UPPERCASE unavailable using Expression.ilike() method!
PostPosted: Wed Jan 30, 2008 12:26 pm 
Newbie

Joined: Wed Jan 30, 2008 11:57 am
Posts: 3
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??


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 31, 2008 7:06 am 
Newbie

Joined: Wed Jan 30, 2008 11:57 am
Posts: 3
Do someone think this should be inserted as an issue? I also tried to write on dev-mailing list... but i didn't receive any answer, impression or suggestion...
:(


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.