JPA repeatable read with optimistic lock: how to determine query results would be affected?

JPA repeatable read with optimistic lock: how to determine query results would be affected? For example,

public class Employee {
     @Id private Integer id;
     private String name;

     @Version private Integer version;

}

// suppose there is an employee called "Scott", id = 1

// transaction T1
Employee emp1 = em1.find(Employee.class, 1, LockModeType.OPTIMISTIC);  // scott

// change the entity in another transaction T2
Employee emp2 = em2.find(Employee.class, 1);  // scott
emp2.setName("Tiger"); 
em2.getTransaction().commit();

// query in the T1
em1.createQuery("select count(e) from Employee e where e.name='scott'").getSingleResult();

What will happen to the last query? Should it throw OptimisticLockException? How a persistence provider would know the locked entity is involved in query and affect the query result?

For repeatable read, the T2 should not affect the query in T1. The query can be a native query.