Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[eclipselink-users] EclipseLink caching behavior

Hi,

I noticed there are quite a lot of discussion about EclipseLink caching, but
couldn't spot this specific case. It seems that updating an Entity causes
the cache to be updated, even the entity is detached. I would not expect
that to happen for a detached object. Actually, I would expect the cache to
be updated only after a successful transaction commit.

Some example code:

        open(true, true, true);  // Creates EMF, EM and begins TX
        Item i1 = new Item("item-1");
        i1.setValue("val-1");
        // First add item
        em.persist(i1);
        close(true, true, false); // Commits TX, closes EM, but does not
close EMF

        // change Item
        i1.setValue("changed");  // Detached now

        open(false, true, true);  // Uses existing EMF, opens EM and begins
TX
        Item i2 = getItem("item-1");  // Fetches item using Query by name
        close(true, true, true);

        System.out.println("i1: " + i1.getValue());
        System.out.println("i2: " + i2.getValue() + ", should be val-1");
        return !i1.getValue().equals(i2.getValue());

So, we
1. add an Entity
2. close the EntityManager making the entity detached
3. change the entity
4. create a new EntityManager
5. fetch the same entity by using it's name field (which is not @Id) in a
query

Current result: in point 5 we get the changed value, i.e. i2.getValue()
returns "changed"
Expected result: in point 5 we get the original value, i.e. i2.getValue()
returns "item-1"

My expectation would be the same even we would be getting the entity (in
point 5) from the same entityManager, but it surprises me even more that the
changed value is returned from a new entityManager.

Any insights? Are my expectations valid? I'm using EclipseLink 1.0.1 in J2SE
mode.
-- 
View this message in context: http://www.nabble.com/EclipseLink-caching-behavior-tp20790844p20790844.html
Sent from the EclipseLink - Users mailing list archive at Nabble.com.



Back to the top