users@glassfish.java.net

Re: How to enable Eager Loading for OneToOne and ManyToOne entity relations

From: <glassfish_at_javadesktop.org>
Date: Tue, 13 May 2008 13:53:25 PDT

Hello,

Thanks for the correction, I did mean J2SE.

As for B being available in the webtier - What you are seeing is the result of a feature of TopLink Essentials. The alternative would have been to throw an exception, or return something indicating the situation - unfortunately the only valid return option would be null which means something else entirely. Since the entity is local to the context, the context is still available (though closed) the feature was requested and implemented allowing it be used to access lazy relations on detached objects.

 This feature still fits with the JPA spec. The behaviour for unaccessed lazy relationships on detached objects is not defined in the spec - it only says when you can access the relation, not what should happen in those other circumstances (such as this one).

Hope this helps explain what you are seeing. If you want to reliably access B regardless of the session being local or remote, your app will need to access the relation before returning it to the webtier.

Best Regards,
Chris
[Message sent by forum member 'chris_delahunt' (chris_delahunt)]

http://forums.java.net/jive/thread.jspa?messageID=274127