openjpa-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dain Sundstrom <d...@iq80.com>
Subject Re: Set query params without TX?
Date Wed, 25 Apr 2007 17:24:53 GMT
On Apr 25, 2007, at 10:22 AM, Patrick Linskey wrote:

>> If I want to have generic code, how am I supposed to
>> implement the createNamedQuery method?  Do I leave the EM
>> open forever?  That doesn't seem right.  So when am I
>> supposed to close the EM?
>
> 1. Create an EM proxy. You've already got one, so we're good there.
>
> 2. The EM proxy should create a new EM for each persistence  
> context. In
> a tx, that means that it hangs onto the EM for the duration of the tx.
> Outside a tx, that means that it keeps the EM open for the duration of
> each operation.
>
> For a find(), that's the duration of the stack execution.
>
> For a query, that means you need to create a Query proxy also, and  
> hand
> off the EM created during createQuery() to the Query proxy. Then, the
> Query proxy is responsible for closing the EM after
> Query.getResultList() / Query.getSingleResult() is exectued.

Ah. That is my problemo.

Thanks,

-dain

Mime
View raw message