gpt4 book ai didi

jpa - 如果未找到 id,EntityManager find() 方法返回 null

转载 作者:行者123 更新时间:2023-12-04 22:04:41 24 4
gpt4 key购买 nike

如果在表中找不到 id,我不明白 find() 方法是否返回 null。在文档中什么也没说。让我们考虑这段代码,其中用户名是表中的主键

  public boolean isUserInDb(String username)
{
boolean isPresent = false;

if(em.find(UserCredential.class, username) != null)
{
isPresent = true;
}

return isPresent;

}

它可以工作吗?

最佳答案

规范说,如果未找到实体,它将返回 null。它应该工作。

文档 here .

关于jpa - 如果未找到 id,EntityManager find() 方法返回 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24129712/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com