Skip to main content

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

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


Back to the top