Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[eclipselink-users] Forcing Lazy Loading Behavior When Desired

Good afternoon, Eclipselink community.  I have a simple question for which hopefully there is a simple answer I'm overlooking.  In a unit test I am writing, I have an entity:

@Entity
public class OptionalFieldEntity {
@Id
private int id;
...
@OneToOne(optional=false)
private OptionalFieldEntityB entB;

@OneToOne(optional=false, fetch=javax.persistence.FetchType.LAZY)
private OptionalFieldEntityB lazyEntB;
...

Now, by default a @OneToOne relationship is fetched EAGERly, but for this unit test's needs I need it to be lazily loaded.  Before the meat of the test execution, I pre-populate the database and assign entB OptionalFieldEntityB(id=1) and lazyEntB OptionalFieldEntityB(id=2) -- the relationships refer to different child entities to ensure the lazy relationship won't benefit from the relationship that is eager by default.  To avoid making the scenario more complicated I turn off the datacache with eclipselink.cache.shared.default=false.

I then close the em and emf and create a new one for the meat of the test.  With the new emf/em, I fetch OptionalFieldEntity, and immediately rollback the transaction and close the em and emf.  No getter/setter methods on the fetched entity are touched.

I then create a new emf so I can get an instance of PersistenceUnitUtil, and observe that the following assertion fails:

            PersistenceUnitUtil puu = emf_test.getPersistenceUnitUtil();
            assertFalse(puu.isLoaded(ofe_find, "lazyEntB"));

So my question is if Eclipselink really is disregarding the LAZY FetchType setting (since the spec says its a hint) then is there a way to make it honor that hint and actually not hydrate OptionalFieldEntity.lazyEntB?

Back to the top