openjpa-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Patrick Linskey" <plins...@bea.com>
Subject RE: Set query params without TX?
Date Wed, 25 Apr 2007 17:22:19 GMT
> 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.

-Patrick

-- 
Patrick Linskey
BEA Systems, Inc.
_______________________________________________________________________
Notice:  This email message, together with any attachments, may contain
information  of  BEA Systems,  Inc.,  its subsidiaries  and  affiliated
entities,  that may be confidential,  proprietary,  copyrighted  and/or
legally privileged, and is intended solely for the use of the individual
or entity named in this message. If you are not the intended recipient,
and have received this message in error, please immediately return this
by email and then delete it. 

> -----Original Message-----
> From: Dain Sundstrom [mailto:dain@iq80.com] 
> Sent: Wednesday, April 25, 2007 10:04 AM
> To: open-jpa-dev@incubator.apache.org
> Subject: Re: Set query params without TX?
> 
> On Apr 24, 2007, at 10:35 PM, Patrick Linskey wrote:
> 
> > Yep -- you've gotta keep it open. If you want to support 
> any JPA impl, 
> > you need to have an EM proxy (please please please make it 
> a dynamic 
> > proxy that implements all the interfaces that the proxied thing 
> > implements).
> 
> That code is from my proxy.
> 
> > If you're happy tying yourself to OpenJPA (or if you want 
> to optimize 
> > for OpenJPA), then you can use the openjpa.AutoDetach 
> property to tell 
> > OpenJPA how to handle non-transactional work. In that scenario, you 
> > can keep a single EM per your delegating instance, and rely 
> on OpenJPA 
> > to do the transactional PC semantics.
> 
> I just might give that a try.
> 
> 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?
> 
> -dain
> 

Notice:  This email message, together with any attachments, may contain information  of  BEA
Systems,  Inc.,  its subsidiaries  and  affiliated entities,  that may be confidential,  proprietary,
 copyrighted  and/or legally privileged, and is intended solely for the use of the individual
or entity named in this message. If you are not the intended recipient, and have received
this message in error, please immediately return this by email and then delete it.

Mime
View raw message