[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [eclipselink-users] EclipseLink caching behavior
|
As you have described it i2's value should not be changed. So you may need
to dig deeper to see what is going on, as it is not correct. Perhaps print
the identity of the objects, and determine when the value gets changed.
Perhaps also set logging to finest.
Ensure that you are creating a new EntityManager for i2, not using the old
one, the old one is still the same persistence context, and will have any
changes made to the objects.
Syvalta wrote:
>
> 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.
>
-----
---
http://wiki.eclipse.org/User:James.sutherland.oracle.com James Sutherland
http://www.eclipse.org/eclipselink/
EclipseLink , http://www.oracle.com/technology/products/ias/toplink/
TopLink
Wiki: http://wiki.eclipse.org/EclipseLink EclipseLink ,
http://wiki.oracle.com/page/TopLink TopLink
Forums: http://forums.oracle.com/forums/forum.jspa?forumID=48 TopLink ,
http://www.nabble.com/EclipseLink-f26430.html EclipseLink
Book: http://en.wikibooks.org/wiki/Java_Persistence Java Persistence
--
View this message in context: http://www.nabble.com/EclipseLink-caching-behavior-tp20790844p20793062.html
Sent from the EclipseLink - Users mailing list archive at Nabble.com.