Thanks for the feedback guys,

Let me elaborate on how the application is working a bit more first since,
as you pointed out, there isn't a general solution for just a desktop
application.

Two SVG canvases are being created during start-up. Per canvas an event
handler is triggered as soon as the SVG file for each canvas is rendered.
This is the cause of the multiple threads and can not be avoided. Once each
handler is triggered I start building up menu's for each canvas, which is
where the entity manager is summoned. At first I only need some basic info
from each menu item (pulled from the DB) but once e.g. a menu item is
clicked I need the rest of the object's properties.


Daryl Stultz 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.
> 

How would one implement the re-fetching? Can this be done in a transparent
way? One would not want to have to consider 'should I re-fetch the object or
not?' before each use of the object.
The only thing I can come up with is e.g. check if a property is 'null' when
its getter is called and if so re-fetch the object. This, however, will
cause re-fetching being done in a lot of cases where it isn't required since
a property could be actually 'null' just as well, thus slowing down the
application unnecessary.

Also, could you give me an example of how re-fetching would be done once the
object exists? Would you just create a query again based on the properties
of the object and provide that to the entity manager or is there a way to
refer to the object to retrieve again in the same way as using 'this' within
an object?


Daryl Stultz wrote:
> 
> 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).
> 

There's only one user so yes, the multi-thread issue comes from the one
user.

-- 
View this message in context: 
http://n2.nabble.com/EntityManager-used-in-multiple-threads-tp3662432p3667942.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

Reply via email to