[jpa-spec users] [jsr338-experts] lazy associations [was Re: Re: Re: changes for 7.6.2 Container-managed Transaction-scoped Persistence Context

From: Linda DeMichiel <>
Date: Fri, 02 Dec 2011 13:33:15 -0800

Thanks, Scott.

Changing the subject and snipping out the previous discussion here so that the
Scott's suggestion doesn't get buried in the thread....

On 12/1/2011 8:37 PM, Scott Marlow wrote:

> I was thinking more about the lazy associations problem. Is there room in the JPA 2.1 specification, to make an
> enhancement that improves what applications experience when the entity manager is invoked outside the scope of a
> transaction? I'm thinking that the container could have a way to give a hint to the persistence provider, that lazy
> fetching should not be used for the entity manager invocation. The advantage of this enhancement, is that applications
> will successfully be able to access the loaded entity(s) that currently fail (due to lazy fetching being used). I think
> that the application can also make changes to work around this (e.g. use FetchType.EAGER) but I would like the same
> (FetchType.LAZY) entity/association to work with both container/app managed entity managers (that don't run in a JTA
> transaction).
> Perhaps this could be a (new) standard property that the container could pass to
> EntityManagerFactory.createEntityManager(Map) that suggests that lazy fetching should be disabled. Or something more
> generic that covers other possible problems. e.g. some hint like "" that lets the provider
> know that loaded entities will be detached (so the provider can avoid using lazy fetching).

Folks, I'd like to get more opinions on this. Should we pursue this direction?
Should we try to address this issue via fetch groups/profiles? Other?