I use JPA (EclipseLink). I have entity class
@Entity
@Table(name = "my_table")
public class MyEntity implements java.io.Serializable {
@Id
@Column(name = "id")
int id;
@Column(name = "name")
String name;
@Lob
@Column(name = "data")
byte[] bytes;
//getters und setters are ommited
}
And I have such query
Query query = entityManager.createQuery("SELECT m FROM MyEntity m WHERE m.name = :name");
After I get result first time, data
field in database changed. But when I run this query next times I still get old value. Can anybody explain me such behavior and show me a way how to get updated value
UPD: I call query.getResultList()
and get instance of MyEntity. Then other application changes data in DB and commit it (I can run sql statement and I see it's really commited). Then I call query.getResultList()
again and get instance of MyEntity that contains old data. My application uses transaction isolation level TRANSACTION_READ_COMMITTED. I've checked this by
Connection c = entityManager.unwrap(Connection.class);
c.getTransactionIsolation();
UPD2: I've noticed that when I invoke the above statement entityManager.unwrap(Connection.class)
the behavior is like cache cleared after this call. After this call I get updated instance by calling query.getResultList()
. I'm totally confused about this.