Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] Question on Eclipselink Internals

Hello Thilo,

What you are seeing is due to the second level cache - a shared cache at the EntityManagerFactory level that EclipseLink uses by default.
The docs describing it and some of the options are here:
http://www.eclipse.org/eclipselink/documentation/2.5/concepts/cache.htm
and http://www.eclipse.org/eclipselink/documentation/2.5/concepts/cache001.htm#CHECCJJD

Basically, the second read is hitting this L2 cache, preventing the A from being loaded from the database. You can either maintain A's bidirectional relationships so the cache is kept in sync, or disable caching for A, or force a refresh. This problem occurs though with reads in the same entityManager as A is incomplete in the L1 cache used by the local em instance, so it is usually recommended that you maintain both sides of bidirectional relationships.

Best Regards,
Chris

On 05/03/2014 6:34 AM, Thilo Tanner wrote:
Hi all,

I mainly used Hibernate and Ebean in the last years. For a new project
I switched to Eclipselink and so far I'm very happy with the results.
The framework is much easier to use, especially if you want to map an
existing DB. Great job!

One thing puzzles me concerning 1:N relationships. I have two very
simple classes:

class A {
   @OneToMany(mappedBy = "a")
   private List<B> bs;
   ...
}

class B {
   @ManyToOne
   private A a;
   ...
}

It seems, that Eclipselink is caching the original object persisted
during runtime. So if I create objects

A a = new A();
em.persists(a);

B b = new B();
b.setA(a);
em.persists(b);

When I access a from another session, I expected that a.getBs() is
filled with the b object created above, which isn't the case.
a.getBs() is empty, unless I create the back-link by hand during
creation:

a.getBs().add(b)

This is the correct and intended behavior for objects created during
runtime, correct? As long as the object isn't updated, I always get
the original object, I once created, from the session, right? Not that
this is an issue, it is just something worth to know when working with
the framework.

Thanks for all your inputs!

Best,
Thilo
_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users



Back to the top