Case-insensitive search using Hibernate

前端 未结 9 1176
长情又很酷
长情又很酷 2021-01-30 16:13

I\'m using Hibernate for ORM of my Java app to an Oracle database (not that the database vendor matters, we may switch to another database one day), and I want to retrieve objec

相关标签:
9条回答
  • 2021-01-30 16:59

    Most default database collations are not case-sensitive, but in the SQL Server world it can be set at the instance, the database, and the column level.

    0 讨论(0)
  • 2021-01-30 17:04

    If you use Spring's HibernateTemplate to interact with Hibernate, here is how you would do a case insensitive search on a user's email address:

    getHibernateTemplate().find("from User where upper(email)=?", emailAddr.toUpperCase());
    
    0 讨论(0)
  • 2021-01-30 17:05

    The usual approach to ignoring case is to convert both the database values and the input value to upper or lower case - the resultant sql would have something like

    select f.name from f where TO_UPPER(f.name) like '%FRAN%'
    

    In hibernate criteria restrictions.like(...).ignoreCase()

    I'm more familiar with Nhibernate so the syntax might not be 100% accurate

    for some more info see pro hibernate 3 extract and hibernate docs 15.2. Narrowing the result set

    0 讨论(0)
提交回复
热议问题