Skip to main content

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

Lazy loading OneToOnes in EclipseLink requires the use of weaving as described here:
http://www.eclipse.org/eclipselink/documentation/2.4/concepts/app_dev007.htm
and http://wiki.eclipse.org/EclipseLink/UserGuide/JPA/Advanced_JPA_Development/Performance/Weaving

Check that you have your classes being woven by using an agent in your JVM or are using the statically woven classes in your tests.

Best Regards,
Chris

On 06/08/2014 4:00 PM, Jody Grassel wrote:
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?


_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/eclipselink-users


Back to the top