NoResultException找不到查询的实体(NoResultException No entity found for query)

编程入门 行业动态 更新时间:2024-10-21 11:48:25
NoResultException找不到查询的实体(NoResultException No entity found for query)

请问我找不到问题在哪里查询它总是让我看到null,即使我手动通过与DB中存储的登录匹配的字符串,当我用“like”更改“=”时,它工作正常,问题与像它返回所有以字符串开头的行我不知道什么是错的,这是我的代码感谢和对我的英语感到抱歉。

public Utilisateur getUserByLogin(String login) { Query req=em.createQuery("select u from Utilisateur u where u.login =:login "); req.setParameter("login", "%"+login+"%"); Utilisateur u = null; try{ u = (Utilisateur)req.getSingleResult(); } catch (NoResultException nre){ } if(u == null){ return null; }else{ return u; } }

please I can't find where is the problem with my query it always show me null even if I pass manually the string that match with login stored in DB, when I change "=" with "like" it works fine, the problem with like it return all rows starting with the string I don't know what's wrong, this is my code thanks and sorry for my english.

public Utilisateur getUserByLogin(String login) { Query req=em.createQuery("select u from Utilisateur u where u.login =:login "); req.setParameter("login", "%"+login+"%"); Utilisateur u = null; try{ u = (Utilisateur)req.getSingleResult(); } catch (NoResultException nre){ } if(u == null){ return null; }else{ return u; } }

最满意答案

尝试

req.setParameter("login", login);

Try with

req.setParameter("login", login);

更多推荐

本文发布于:2023-08-07 19:08:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1465567.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:找不到   实体   NoResultException   entity   query

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!