Providing an escape sequence for Criteria queries

Description

Up to now, there is no way of setting the escape sequence to use for string comparisions with like for Criteria queries.

This is necessary as MySQL on the one hand and HSQLDB / Oracle on the other behave differently...

If you want to search for '_abc' in MySQL, you have to use:
value like '
_abc'

In Oracle or HsqlDB, you have to use:
value like '_abc'

If you want to switch to another escape sequence like '|' , you can set it in HQL with value like '|_abc' escape '|'. Unfortunately, there is no way of setting it for Criteria queries, which would force me to rewrite all my Criteria queries in HQL. It would really be nice if the feature/improvement would be added...

Environment

Hibernate 3.1.3, MySQL, HSQLDB, Oracle

Activity

Show:
Max Rydahl Andersen
April 6, 2008, 4:39 PM

Mark - create a subclass that calls the method like you want. That is the intented usecase for customizations.

Mark A. Ziesemer
April 6, 2008, 6:55 PM

Max - thanks for confirming that subclassing is the intended usecase for these classes.

However, I'd still be curious as to the reasoning behind the protected constructors, just as Kevin previously asked without receiving an answer. While creating the subclass works, it seems a bit inconvenient to have to create a subclass just to access code that already exists. Is there a reason as to why the protected constructors aren't / can't be public?

Thanks!

Max Rydahl Andersen
April 6, 2008, 8:16 PM

I assume it was done like because the author were not sure if he would like that constructor to be public api.

Nabeel Siddiqui
December 30, 2008, 12:54 PM

On a related note the LikeExpression seems to have a bug in the method getTypedValues(). Its converting the value to lower case without checking the ignoreCase flag. So it does not work when ignoreCase is false. Is it intended?

Mark A. Ziesemer
December 30, 2008, 4:36 PM

Nabeel - the issue you mentioned regarding ignoreCase is already being tracked at HHH-2997.

Assignee

Unassigned

Reporter

Tobias Dietl

Fix versions

None

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

Priority

Major
Configure