The Artima Developer Community
Sponsored Link

Java Buzz Forum
Hibernate: Case Insensitive Searches

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Geoffrey Wiseman

Posts: 51
Nickname: diathesis
Registered: Aug, 2003

Geoffrey Wiseman is a software professional.
Hibernate: Case Insensitive Searches Posted: Nov 15, 2005 1:35 PM
Reply to this message Reply

This post originated from an RSS feed registered with Java Buzz by Geoffrey Wiseman.
Original Post: Hibernate: Case Insensitive Searches
Feed Title: Furious Purpose
Feed URL: http://www.jroller.com/diathesis/feed/entries/rss
Feed Description: Thoughts and experiences on technology and software.
Latest Java Buzz Posts
Latest Java Buzz Posts by Geoffrey Wiseman
Latest Posts From Furious Purpose

Advertisement

It's just been one of those days. I want a simple case-insensitive search in Hibernate 2.X, which ... has turned out to be surprisingly painful.

Functions: Database and JDBC Scalar Escapes
Hibernate supports using database-specific functions like UPPER(), but I can't find any sign that it does or does not support JDBC function escape syntax that would be somewhat more cross-platform. I have the feeling I've looked for this before.

Criteria Api
Since I'd rather not make my queries database-specific, I thought I'd check in the criteria API to see if there was any support there. It seems that there is: the EqExpression class supports an 'ignoreCase' parameter. Unfortunately, since that isn't exposed through the Expression facade (e.g. Expression.eq())), this took me more time to discover.

Criteria MatchMode.EXACT
However, I also discovered something unexpected that could lead to some minor vulnerabilities in applications that use Hibernate.

Hibernate enables you to perform like and case-insensitive like expressions using Expression.like(). You can apply MatchMode to indicate if you want the expression to be found at the start, at the end, or to be an exact match, and MatchMode will put the requisite '%' wildcards in place for you.

What I've discovered is that MatchMode.EXACT does only half of what I had expected; it doesn't add any wildcards, but doesn't escape any wildcards that you might have already inserted. This capability is useful -- If I want to search for LIKE 'J%Smith', I can. I'm just worried that some developers might expect, as I had, that EXACT means that wildcards are not in play, and accidentally expose more power to their users than they had intended.

Read: Hibernate: Case Insensitive Searches

Topic: [Nov 7, 2005 11:44 PST] 21 Links Previous Topic   Next Topic Topic: JBuilder duplicate code detection - with screenshot!

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use