Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[eclipselink-users] Refreshing lists

Hi,

I am working on a small project that involves jersey (jax-rs), JPA
(provided by eclipselink), and guice.  My jersey resources are created
by guice, which also injects an EntityManager into them.  There is
just one EntityManagerFactory instance, and it is owned by the
injector.

The resource then, for every request, creates an EntityManager, gets a
List<Item>, and sends the result back as the response.

The resource looks like this:


@Path("/list")
public class MyResource {
    @Inject @Named("MyTestEntity")
    private EntityManager em;

    @GET
    @Produces("text/plain")
    public String getIt() {
        log.debug("returning something");

        if(em == null) {
            return "no database";
        } else {
            Query q = em.createNamedQuery("Item.findAll");
            List<Item> items = q.getResultList();
            StringBuilder sb = new StringBuilder();
            for(Item p : items)
            {
                sb.append(p.getPlatformId() + "\n");
            }

            em.close();
            return sb.toString();
        }
}


Here's the thing I'm not getting.  When I do the first query it takes
a fairly long time as it gathers up all the data.  When I do the
second and subsequent queries it takes no time at all.  It doesn't
consult the database at all; it just looks in the cache.

I can see how to do en.refresh(anItem) but what I want to do is cause
it to refresh the ENTIRE LIST.  The problem is, this web service isn't
the only thing accessing this data - external applications are
constantly adding and updating records.

I can set a queryHint that causes a refresh, but it seems that's not
really the right thing to do.  For one, that would be
eclipse-specific, and the whole point of me using JPA is to avoid
implementation-specific APIs (even thought I can't really see myself
using anything other than eclipselink in the near future).


I have looked all over but have yet to find a clear example of how
this is supposed to work in, say, a grizzly or tomcat environment.  I
want to maximize performance, meaning pooling connections etc.


The other problem I have is that, according to logs, it seems to
prepare the same statements over and over and over ... unless for some
reason         p.put("eclipselink.logging.level.sql", "FINE") is lying
to me.  It doesn't seem to be... it really does seem to generate a LOT
of traffic to retrieve relatively simple things.  It's a fully linked
database with many relationships; still...


--Chris


Back to the top