This sample does not work as I expect. Why? Is it a bug? Below is the complete program.
Expect: 3
Get: 4
import java.io.Serializable; import java.util.List; import javax.persistence.*; @Entity public class Update implements Serializable { @Id int i; int v; public static void main (String[] args) { EntityManagerFactory emf = Persistence.createEntityManagerFactory("ODB.odb"); EntityManager em = emf.createEntityManager(); em.getTransaction().begin(); Update simple = new Update(); simple.i = 0; simple.v = 3; em.persist(simple); em.getTransaction().commit(); simple.v = 4; em.getTransaction().begin(); simple = em.createQuery("SELECT s FROM Update s" , Update.class) .getResultList().listIterator().next(); System.out.println(simple.v); } }