Hi,

Lazy loading is perfectly possible, but you have to remember that the entities 
are only managed for as long as the Global transaction in which they were 
loaded is active.

If you commit the transaction that was used to look up the entity then it will 
be detached and no longer be able to load any lazy state. As long as you access 
the lazy field within the scope of that transaction then it will give you the 
behaviour you want.

Regards,

Tim

________________________________
> Date: Tue, 9 Nov 2010 09:08:42 +0800
> Subject: JPA Lazy loading problem
> From: [email protected]
> To: [email protected]
>
> Hi
>
> I'm following the blog sample design.
> I have a persistence layer and several entities.
> The problem is when returned objects from persistence service,
> I can't the OneToMany(Or ManyToOne) field which marks FetchType=LAZY, I
> have to make it EAGER.
>
> It gives out null pointer exception, I think it has something to do
> with EntityManager scope.
> My entity has filed like lost of pictures, which I don't think make it
> load EAGER is a good idea.
>
> Is there anyway I can use lazy loading or some work around?
>
> Regards
> LongkerDandy
                                          

Reply via email to