On Thu, Sep 17, 2009 at 7:20 AM, Prodoc <[email protected]> wrote: > > Hi, > > I've created a desktop application using OpenJPA 1.2.1. Due to the large > amount of data in the DB lazy fetching is basically a must. Large > collections in some entity classes aren't accessed right away after > retrieving the objects from the DB so the entity manager has the remain > open.
I am writing a web application so my options are different than yours. I (lazily) create an em per "event thread" (essentially per HTTP request) that gets destroyed at the end of the request. It's common to load some entities and display some "top level" information - like a list that shows the name, modification date, etc. Then drill into one object and work with its details. Here I would re-fetch the entity from the DB pulling along whatever extended properties/children I need. A Soldier may have only a few Weapons, but an Army may have millions. The property Army.weapons needs to exist so you can use it in queries, but you would never want to traverse it in Java because the whole thing would be loaded from the DB. So as well as the idea above, you can work with an entity's extended properties and children without having them all loaded into one object graph. In the case of a desktop application, you may want to consider keeping an entity manager per user (unless the multi-thread issue comes from the one user). -- Daryl Stultz _____________________________________ 6 Degrees Software and Consulting, Inc. http://www.6degrees.com mailto:[email protected]
