【问题标题】:EntityManager find() method returns null if the id is not found如果没有找到 id,EntityManager find() 方法返回 null
【发布时间】:2014-06-09 21:55:27
【问题描述】:

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

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

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

    return isPresent;

}

可以吗?

【问题讨论】:

    标签: jpa entitymanager


    【解决方案1】:

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

    文档here

    【讨论】:

      猜你喜欢
      • 2014-02-07
      • 2018-11-24
      • 1970-01-01
      • 2020-02-05
      • 2014-11-26
      • 2023-04-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多