Query Cache in 2.4.1 Help [message #1044190] |
Thu, 18 April 2013 11:42  |
Eclipse User |
|
|
|
We've just started using EclipseLink and I'm having an issue using the QueryCache.
I have a named query which I setup following the example at http://wiki.eclipse.org/EclipseLink/UserGuide/JPA/Basic_JPA_Development/Caching/Query_Cache
@NamedQuery(name = "CustomField.loadAll",
query = "select cf from CustomField cf",
hints = {
@QueryHint(name = QueryHints.QUERY_RESULTS_CACHE, value = HintValues.TRUE),
@QueryHint(name=QueryHints.QUERY_RESULTS_CACHE_SIZE, value="1")})
Now when the query is run the query cache is only updated if there are no results. I believe that this is caused by the fact that in ReadAllQuery if the results are empty then following is executed
this.temporaryCachedQueryResults = InvalidObject.instance();
If however there are results they are never cached because in org.eclipse.persistence.internal.descriptors.ObjectBuilder#buildObject
session.isUnitOfWork is true which means the cacheResult method on the query is never called.
So either it's a bug that the empty results are cached or that results are not, I believe the former.
Any help with this would be greatly appreciated.
Regards
Howard
|
|
|
Re: Query Cache in 2.4.1 Help [message #1047675 is a reply to message #1044190] |
Tue, 23 April 2013 10:04  |
Eclipse User |
|
|
|
How do you execute the query? Do you have changes made in your persistence context, or have you called flush() or executed a native SQL query?
The query results cannot be cached if you have potentially changed the data in a transaction. I assume this is what you have done.
I believe it is a bug that the empty results are being cached, if you are in an early transaction, they should not be cached.
You can execute your query at the start of the transaction before changing anything, or you can execute it as a read-only query.
|
|
|
Powered by
FUDForum. Page generated in 0.04310 seconds