Hibernate version: 3.1
Code between sessionFactory.openSession() and session.close():
Code:
List topicList =
getSession().createCriteria(Topic.class)
.add(Expression.like("topicShortName", topicShortName,
MatchMode.START))
.list();
Name and version of the database you are using: DB2
The generated SQL (show_sql=true):Code:
select this_.AUTOWR_GRP_ID as AUTOWR1_0_0_, this_.AUTOWR_TPC_SHRT_NA as AUTOWR2_0_0_, this_.AUTOWR_TPC_DESC as AUTOWR3_0_0_, this_.RCVR_UID_CD as RCVR4_0_0_, this_.MSG_PRI_CD as MSG5_0_0_ from AUTOWR_TPC_12753 this_ where this_.AUTOWR_TPC_SHRT_NA like ?
I know that this question has been asked in the past, but I did a search and found only unanswered posts.
I would like to use a Criteria Query to perform a LIKE wildcard search, but our business requirements allow for data containing underscores. Since underscores and percent signs are the SQL wildcards used with LIKE, a search for a field starting with "test_"% might return "test_page" and "tests". The users want to only see the row for "test_page" for this example.
I have gotten this to work using HQL and SQL by adding an "ESCAPE '\'" clause at the end of the provided query string. Is this possible using criteria queries? Is there a method that I have not found to provide an escape character that Hibernate would escape in the match criteria for like and or ilike?
Thanks in advance,
Ryan