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

From: Michael Bouschen <>
Date: Mon, 5 Dec 2011 23:33:45 +0100


I agree, fetch groups allow to control the relationships being loaded
together with an entity, so this would address the the lazy associations

Regards Michael

> On 2 déc. 2011, at 22:33, Linda DeMichiel 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?
> Yes the fetch groups/profile is the right place to address this problem.

*Michael Bouschen*
akquinet tech_at_spree GmbH
Bülowstr. 66, D-10783 Berlin
Fon:   +49 30 235 520-33
Fax:   +49 30 217 520-12
Web: <>
akquinet tech_at_spree GmbH, Berlin
Geschäftsführung: Martin Weber, Dr. Torsten Fink
Amtsgericht Berlin-Charlottenburg HRB 86780 B
USt.-Id. Nr.: DE 225 964 680