The SQL keywords "LIKE ... ESCAPE" is not recognized by a Hibernate filter in EAP 6.

Solution Verified - Updated -

Issue

If the "LIKE ... ESCAPE" clause is defined in a Hibernate filter, for example:

 @Entity
 @FilterDef(name="ignoreSome", parameters={@ParamDef(name="youraddress", type="string")})
 @Filter(name="ignoreSome", condition="address like :youraddress escape '\'")
 public class Member implements Serializable {

when the filter is enabled, the following errors are thrown:

Caused by: org.h2.jdbc.JdbcSQLException: Syntax error in SQL statement "SELECT THIS_.ID AS ID1_0_0_, THIS_.ADDRESS AS ADDRESS2_0_0_, THIS_.EMAIL AS EMAIL3_0_0_, THIS_.NAME AS NAME4_0_0_, THIS_.PHONE_NUMBER AS PHONE5_0_0_, THIS_.STARTDATE AS STARTDAT6_0_0_ FROM MEMBERHIBERNATE4DEMO THIS_ WHERE THIS_.ADDRESS LIKE ? THIS_[*].ESCAPE '' ORDER BY THIS_.NAME ASC "; SQL statement:
select this_.id as id1_0_0_, this_.address as address2_0_0_, this_.email as email3_0_0_, this_.name as name4_0_0_, this_.phone_number as phone5_0_0_, this_.startDate as startDat6_0_0_ from MemberHibernate4Demo this_ where this_.address like ? this_.escape '' order by this_.name asc [42000-168]

Please note that the key word "escape" is interpreted as a column name:
where this_.address like ? this_.escape ''

A similar query works fine with JPA Query object.
For example:

  Query query = em.createQuery("from Member where address like :youraddress escape '\'");
  query.setParameter("youraddress", "Brno%");

Environment

  • JBoss Enterprise Application Platform(EAP) 6.1.1

Subscriber exclusive content

A Red Hat subscription provides unlimited access to our knowledgebase of over 48,000 articles and solutions.

Current Customers and Partners

Log in for full access

Log In
Close

Welcome! Check out the Getting Started with Red Hat page for quick tours and guides for common tasks.