users@glassfish.java.net

Re: Entity cache and named query

From: <glassfish_at_javadesktop.org>
Date: Mon, 15 Sep 2008 17:40:21 PDT

> Hello,
>
> Is it true that Entities that use named query that
> are complex aren't cached ?

Best of my knowledge, that's not true (specifically in regards to Toplink Express).

What happens is that the JPA will make an actual SQL call to the server -- this will always happen.

Upon return, if any of the entities that are in the result also happen to be cached, the JPA will use the cached entities rather than the data from the query.

Mind, this is dependent on the nature of the query of course (notably assuming that it's returning entire entities, and not just a collection of scalars).

So, in the sense that the JPA will always make a call to the backing database, then, it's true that the queries aren't "cached". But in terms of the actual data returned by the query to the call, it may well be cached.

Finally, the Toplink makes it a point to bind variables to queries, so most likely the actual SQL statement will be cached on the backend database, but that's database specific and out of scope for the JPA. Rather, Toplink is aware the many databases do this and tries to be friendly to such databases. This statement cache helps reduced parsing and processing time on the back end.
[Message sent by forum member 'whartung' (whartung)]

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