简体   繁体   中英

how to make toUpperCase in hibernate Restrictions

I wrote my code like this

criteria.add(Restrictions.eq("lastName", "ChARaN").ignoreCase()); //

This by default converting both to lower case.

SQL generated:

select
    this_.ID as ID1_0_0_,
    this_.EMAIL as EMAIL2_0_0_,
    this_.FIRST_NAME as FIRST_NA3_0_0_,
    this_.LAST_NAME as LAST_NAM4_0_0_ 
from
    Employee this_ 
where
    

    14:56:57,017 TRACE BasicBinder:81 - binding parameter [1] as [VARCHAR] - 

I want Hibernate to generate query for uppercase like:

where
       (this_.LAST_NAME)=?

Not sure what advantage would it have if it uses UPPER instead of LOWER . Having said that you try below option to force Hibernate to use UPPER

criteria.add(Restrictions.sqlRestriction("UPPER({alias}.lastName) = UPPER(?)", "ChaRaN", StringType.INSTANCE))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM