|
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 ''
I've run a similar query using the Query object, everything works fine. For example: Query query = em.createQuery("from Member where address like :youraddress escape '\'"); query.setParameter("youraddress", "Brno%");
The "LIKE ... ESCAPE" query is supported in JPA based on the spec. So, is this a Hibernate bug or something that's not supported in Hibernate Filter?
I'm attaching a simple reproducer here for your reference.
Please take particular look at org.jboss.as.quickstart.hibernate4.model.Member and org.jboss.as.quickstart.hibernate4.data.MemberRepository (findAllOrderedByAddressFilter)
|