Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EntityManager find() method returns null if the id is not found

I'm not understanding whether the find() method return null if the id is not found in the table. In the documentation doesn't say anything. Let consider this code where the username is the primary key in the table

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

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

    return isPresent;

}

could it work?

like image 451
Mazzy Avatar asked Oct 16 '25 17:10

Mazzy


1 Answers

The spec says it will return null if the entity was not found. It should work.

Documentation here.

like image 95
ra2085 Avatar answered Oct 19 '25 07:10

ra2085