Unexpected behaviour upon update. Bug?


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.*;

public class Update implements Serializable
    int i;
    int v;

    public static void main (String[] args)
        EntityManagerFactory emf =
        EntityManager em = emf.createEntityManager();

        Update simple = new Update();
        simple.i = 0;
        simple.v = 3;

        simple.v = 4;
        simple = em.createQuery("SELECT s FROM Update s" , Update.class)

It seems to work as expected. The entity object is cached in the EntityManager as a managed entity object and it is returned with the update from the query.

Changes in one EntityManager instance are invisible in other EntityManager instances until commit, but visible in the EntityManager in which they occurred.

ObjectDB Support
ObjectDB - Fast Object Database for Java (JPA/JDO)

Post Reply

To post a reply and/or subscribe to update notifications - please login