As others mentioned there are a few solutions,
Using @Query
@Query(value = "from Pharmacy where id = :id")
Optional<Pharmacy> findById(Long id);
The one that probably takes the least to implement is
Optional<Pharmacy> findOneById(Long pharmacyId);
since findOneById is not part of Jpa it doesn't call EntityManager.find and filters are correctly applied.