users@cargotracker.java.net

Re: Potential Lazy Loading Issue (was: Question about CargoTracker)

From: Reza Rahman <Reza.Rahman_at_oracle.com>
Date: Fri, 11 Oct 2013 13:22:50 -0400

Thanks a lot of the kind words and great catch indeed! The reason this
works properly is that EclipseLink handles lazy loading in detached
entities gracefully (as compared to say Hibernate). We probably would
have ran into an issue if attempting to port to WildFly/JBoss AS.

There are several ways of handing this situation without relying on the
good graces of EcliseLink - keep an extended persistence context alive
across the view, keep an open transaction across the view or loading the
required data based on the use case. While perhaps not elegant, the
simplest/most scalable solution I applied in my past consulting practice
is to load the required data in the repository layer (by passing in a
general purpose flag for certain use cases). Any suggestions you may
have in this regard would be very welcome since you spotted the
potential problem :-).

Either way, we should really discuss this and address the problem. Would
you mind helping us out by creating a JIRA entry:
https://java.net/jira/browse/CARGOTRACKER so this does not get lost?

Do let us know how things go with running the application. Perhaps the
best place to get started is the read me file:
https://java.net/projects/cargotracker/sources/svn/content/readme.txt.

P.S.: Feel free to use our user forum (copied). Also contributors are
always welcome :-).

On 10/11/2013 11:15 AM, Dan Peterström wrote:
> Hi
>
> My name is Dan and I am EE developer. I liked you example project
> demonstrating DDD very much, good examples like this has been missing.
> What I wanted to look into was how you handled lazy loading in your
> application as I feel this is central for having a good DDD design. I
> started looking at one one-to-many relation List<Leg> legs in the
> Itinerary class that is embedded in the Cargo class.
>
> The facelet track.xhml calls leg.expected which in
> CargoTrackingViewAdapter does
> cargo.getItinerary().isExpected(handlingEvent);
>
> Im wondering why this method does not throw a lazy initialization
> exception. The eclipselink one-to-many relationship is default lazy
> and there is no ejb session associated with the CargoRepository which
> fetches the entity, so the cargo object should be detached from the
> JPA session.
>
> Please enlighten me to what I am missing.
>
> (I havent actually run the application just examined the code)
>
> Regards,
> Dan
>