CascadeType.REFRESH does not work for MySQL

Hello! I have an application with 2 classes, Person and Phone. The classes look like this.

@Entity
public class Person {

@Id
@GeneratedValue(generator = "ID_GENERATOR")
private Long id;

@NotNull
private String name;

@OneToMany(cascade = {CascadeType.PERSIST, CascadeType.REFRESH})
@JoinColumn(name = "PERSON_ID", nullable = false)
private Set<Phone> phones = new HashSet<>();


}

@Entity
public class Phone {

@Id
@GeneratedValue(generator = "ID_GENERATOR")
private Long id;

@NotNull
private String owner;


}

I change the owner of a phone from a different thread and refresh the person:

Executors.newSingleThreadExecutor().submit(() → {

        EntityManager em1 = emf.createEntityManager();
        em1.getTransaction().begin();

        em1.unwrap(Session.class).doWork(con -> {
            PreparedStatement ps = con.prepareStatement(
                    "update PHONE set OWNER = ? where PERSON_ID = ?"
            );
            ps.setString(1, "John Jones");
            ps.setLong(2, PERSON_ID);
            ps.executeUpdate();
        });

        em1.getTransaction().commit();
        em1.close();
        return null;
    }).get();


    em.refresh(john2);
   for (Phone phone : john2.getPhones()) {
        assertEquals("John Jones", phone.getOwner()); //1
    }

The assert from line //1 fails for MySQL, although the information was changed in the database. However, moving to H2 with absolutely the same code makes the assert from //1 to succeed.
Am I missing anything or could this be a bug?

I can provide the whole code if needed.

Thank you!

The default transaction isolation level for MySQL is REPEATABLE_READ whereas for most other databases like H2, it is READ_COMMITTED. If a transaction, like in your case for em is started at t1, and another transaction commits a change, in you case em1, at t2 the transaction started at t1 can’t see changes of t2 since t2 started after t1. You can change the default isolation level on the JDBC driver though. You can add the following to your JDBC connection URL ?sessionVariables=transaction_isolation='READ-COMMITTED' but there might be other possibilities to set the transaction isolation level, depending on the environment you are running in.

Crystal clear! This explains everything. Thank you so much for your response!