users@glassfish.java.net

Re: Entity cache and named query

From: <glassfish_at_javadesktop.org>
Date: Wed, 17 Sep 2008 06:19:21 PDT

Hello,

I'm guessing TopLink express was a reference to TopLink Essentials (which was based on TopLink, but with a few less features). EclipseLink is also based on TopLink but has everything and more. EclipseLink will be the JPA 2.0 RI and the default JPA provider in glassfish moving forward.

Because of the differences, they do work a little bit different in regards to queries hitting the database. I'd recommend looking at Wonseok's blog:
  http://weblogs.java.net/blog/guruwons/archive/2006/09/understanding_t_1.html
for a great explaination on caching which is relevant to both.

Simple queries that only search for an entity based on its primary key may not hit the database. If they are in the local transaction cache, they are returned from it - no SQL is issued. If they are not there, what happens next depends on the transactional context. It could go to the shared cache - if its there it will return it without going to the database. If its not there, or you have done something in the transaction that might make the shared cache results unreliable such as a stored procedure, it will pull the entity from the database.

Non-simple queries in TopLink essentials will go to the database. SQL will be issued but if the entities exist in the local cache, they are not rebuilt. Instead, the entities as they exist in the cache are returned. So the cache still improves performance, since rebuilding entities is expensive. EclipseLink has the ability to do in memory queries. So it can be configured to do supported queries in the cache without hitting the database at all. Since in memory queries may or may not be faster than issuing the sql to the database and letting it return a resultset, they are completely configurable.

Hope this helps.

Regards,
Chris
[Message sent by forum member 'chris_delahunt' (chris_delahunt)]

http://forums.java.net/jive/thread.jspa?messageID=299827