SQL 'LIKE' operator in Hibernate Criteria API

后端 未结 5 1471
萌比男神i
萌比男神i 2020-12-16 14:55

I want to implement some universal filter with Hibernate Criteria. It should work like LIKE operator from SQL:



        
5条回答
  •  心在旅途
    2020-12-16 15:35

    I recommend using a Query object instead of the Criteria object, in this case.

    I can't remember if Criteria passes things it doesn't understand straight through to the database like a Query object will do. Basically what this would mean is that if you used a function that was database specific that the Hibernate parser didn't understand, it would pass it "as is" to the database.

    Example:

    Query queryObject = session.createQuery("from ClassName where VARIABLENAME like '%'||anyvaluehere||'%' order by VARIABLENAME");
    List resultList= queryObject.list();
    

    For more see here

提交回复
热议问题