使用Like和%%运算符的Hibernate命名查询? [英] Hibernate Named Query Using Like and % % operators?

查看:145
本文介绍了使用Like和%%运算符的Hibernate命名查询?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Hibernate JPA示例代码中.

In my Hibernate JPA Sample code..

public List<AttendeesVO> addAttendees(String searchKeyword) {
    TypedQuery<AttendeesVO> query = entityManager.createQuery(" select at from AttendeesVO at where at.user.firstName LIKE :searchKeyword",AttendeesVO.class);
    query.setParameter("searchKeyword", searchKeyword+"%");
    return query.getResultList();
}

在给出整个字符串firstName=Narasimham

但是当我们给任何字符Narasimhaman

But it is not working when we give any character of Narasimham i.e a or n

实际上我的想法是我给Like运算符加上% %以便它可以处理给定String的任何字符.

Actually my thinking is i'm giving Like operator with % % so it working any character of given String..

推荐答案

您正在使用query.setParameter("searchKeyword", searchKeyword+"%");

而不是query.setParameter("searchKeyword", "%"+searchKeyword+"%");

第一个将返回Narasimham N Na Nar Nara等的行.

first one will return rows for Narasimham N Na Nar Nara etc.

这篇关于使用Like和%%运算符的Hibernate命名查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆