Sorry, my problem is not yet solved. FetchPlan.removeField seems to only work for fields that were explicitly added and not for fields that are in the default fetchgroup. My guess is that the system cannot handle explicitly overriding individual eager fetched to become lazy. Is this true?
The only thing I now know (to solve the problem of not fetching an @Embedded without marking everything inside as lazy) is to: fetchPlan.removeFetchGroup(FetchPlan.GROUP_DEFAULT); And then add individual fields back in: fetchPlan.addField(Department.class, "id"); fetchPlan.addField(Department.class, "name"); Unfortunately this is not going to work for me because removing the default fetchgroup also removes all individual fields for unrelated entities that are fetched with the same entityManager. This is in fact the case for me because there is an almost independent piece of code that runs within the same transaction and fetches another entity. I guess an OpenJPA-specific annotation for lazy-fetching an embeddable would solve my problem. Any other possible solution than making this feature request would be greatly appreciated. Regards, Henno -----Oorspronkelijk bericht----- Van: Henno Vermeulen [mailto:[email protected]] Verzonden: woensdag 11 mei 2011 15:01 Aan: '[email protected]' Onderwerp: RE: lazy fetch @Embedded Oops sorry, I think I found a solution to my question. Support for removing an embeddable exists through the FetchPlan API itself (especially since https://issues.apache.org/jira/browse/OPENJPA-1486 is fixed?). I solved my problem by doing: FetchPlan fetchPlan = entityManager.getFetchPlan(); fetchPlan.removeField(Department.class, "address"); fetchPlan.removeField(Department.class, "alternativeAddress"); The drawback of this is that you have to repeat this code each time you fetch a Department; it does not become part of any @FetchGroup configuration on the entity itself. -----Oorspronkelijk bericht----- Van: Henno Vermeulen [mailto:[email protected]] Verzonden: woensdag 11 mei 2011 14:44 Aan: '[email protected]' Onderwerp: lazy fetch @Embedded I am using fetch plans and I can lazy fetch individual attributes with @Basic(fetch = FetchType.LAZY), but now I have an entity with an embeddable which must sometimes be lazy fetched. Is it possible to lazy fetch an embeddable without having to annotate each of the embeddable's attributes with @Basic(fetch = FetchType.LAZY)? Regards, Henno Vermeulen
