如果找不到id,EntityManager find()方法返回null

Maz*_*zzy 3 jpa entitymanager

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

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

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

    return isPresent;

}
Run Code Online (Sandbox Code Playgroud)

它可以工作吗?

ra2*_*085 7

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

文档在这里.