openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michael Dick <>
Subject Re: EntityManager used in multiple threads
Date Thu, 17 Sep 2009 19:19:02 GMT
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


Hope this helps,

On Thu, Sep 17, 2009 at 7:00 AM, Daryl Stultz <> wrote:

> On Thu, Sep 17, 2009 at 7:20 AM, Prodoc <> 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.

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message