openjpa-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Patrick Linskey" <>
Subject RE: extending the life of a LRS query
Date Mon, 11 Dec 2006 10:09:50 GMT
This approach would require that the full results be enlisted in cache
(i.e., traversed) prior to the EM being closed. That may or may not be
what you're looking for.

If what you're looking for is to hold the cursor to the DB open across
multiple requests, you'll need to create an extended-persistence-context
EM (either via a stateful session bean or via using a non-JTA entity
manager, obtained through an EMF), and then do the query in that EM and
bind the query into session state somewhere. Of course, all the normal
cautions about keeping database connections open across multiple
requests apply.

If you're just looking to page through results for a search-result-style
listing, you might be interested in the JPA Query.setFirstResult() and
Query.setMaxResults() calls -- these allow for efficient (but
non-isolated) paging through queries. Don't forget to add an ordering to
your query when you do this, of course. Oh, and OpenJPA is smart about
using range data in the query cache.


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 [] 
> Sent: Saturday, December 09, 2006 9:24 AM
> To:
> Subject: Re: extending the life of a LRS query
> I am by no means an OpenJPA expert, but I did see something related  
> to this when reading the docs yesterday.  OpenJPA has a  
> QueryResultsCache where it keeps the results of a query so if 
> you run  
> the query again you get the same results (I'm not sure if that is  
> what you want).  Here is the code from the docs:
> OpenJPAEntityManagerFactory oemf = OpenJPAPersistence.cast(emf);
> QueryResultCache qcache = oemf.getQueryResultCache();
> EntityManager em = emf.createEntityManager();
> Query pinQuery = em.createQuery(...).
>      setParameter(0, paramVal0).
>      setParameter(1, paramVal1);
> Query unpinQuery = em.createQuery(...).
>      setParameter(0, paramVal0).
>      setParameter(1, paramVal1);
> qcache.unpin(unpinQuery);
> Hope that helped.
> -dain
> On Dec 8, 2006, at 8:04 PM, roger.keays wrote:
> >
> > Hi,
> >
> > I'm trying to use OpenJPA's fetch plan extensions to have a query  
> > return a
> > large result set. It seems to work okay, except that the LRS gets  
> > closed /
> > detached with the EntityManager, which only makes it useful 
> for one  
> > request.
> > Is it possible to have the LRS stay open after the em has been  
> > disposed?
> >
> > Thanks,
> >
> > Roger
> > -- 
> > View this message in context: 
> > life-of-a-LRS-query-tf2784490.html#a7769269
> > Sent from the open-jpa-dev mailing list archive at

View raw message