I think Daryl's suggestion of creating an EntityManager for each user is your best solution. Having multiple threads access the same EntityManager is generally not a good idea (easy to shoot yourself in the foot).
If you're concerned with load on the database you can enable the built in DataCache [1] so entities fetched from the DB will be shared between EntityManagers. [1] http://openjpa.apache.org/builds/latest/docs/manual/manual.html#ref_guide_cache_conf Hope this helps, -mike On Thu, Sep 17, 2009 at 7:00 AM, Daryl Stultz <[email protected]> wrote: > 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] >
