开发者

match query in hibernate for two characters

I am using Hibernate with mysql I have a keyword in my java for which i need to retrieve record from MySQL

    Restrictions.li开发者_运维知识库ke("resume Text", keyword, Match Mode.ANYWHERE));

when i send keyword as test it works ,when i send keyword as sample it works BUT when i send keyword as test,sample it fails,don't return any result.

Any Solution

thanks


You can't pass in multiple values to the single-valued value parameter of like.

Try using Restrictions.or to construct you logic, like this:

Restrictions.or(
    Restrictions.like("resume Text", "test", Match Mode.ANYWHERE),
    Restrictions.like("resume Text", "sample", Match Mode.ANYWHERE)
);

Or use Restrictions.and instead, depending on the matching logic you are trying to achieve


Bohemian is spot on but if you would have more than 2 or-clauses then you're probably better of using Disjunction (or) or Conjunction (and):

        Disjunction orClause = Restrictions.disjunction();
        orClause.add(Restrictions.like("resume Text", "test", Match Mode.ANYWHERE));
        orClause.add(Restrictions.like("resume Text", "test", Match Mode.ANYWHERE));
        orClause.add(...)
        criteria.add(orClause);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜