Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] Cannot get a cache hit on entity!

Odd, since errorCode is the Id you should get a cache hit.  Ensure that the
object is in the cache and that you have caching enabled.  Is errorCode the
only id, or is it a composite Id?

Are you using any cache or transaction properties, what environment are you
using (i.e. Spring?)? Include your persistence.xml.  What version of
EclipseLink are you using?  Are you using flush() before the query?

The query cache should also work, but should not be required for an ID
query.  Can't see how you would get no results found.

Since it is an Id query, you could just use find() with the Id.  That will
check the cache, assuming you have caching enabled.



cj91 wrote:
> 
> I have the following entity:
> 
> 
> 
> @Entity
> 
> @Table(name = "ERR_TEXT")
> 
> @NamedQuery(name = "getErrorText", query = "select errText from ErrText
> errText where errText.errorCode = :errorCode", hints = {
> 
>                 @QueryHint(name = QueryHints.CACHE_USAGE, value =
> CacheUsage.CheckCacheThenDatabase),
> 
>                 @QueryHint(name = QueryHints.QUERY_TYPE, value =
> QueryType.ReadObject),
> 
>                 @QueryHint(name = QueryHints.READ_ONLY, value =
> HintValues.TRUE) })
> 
> @Cache(shared = true, type = CacheType.WEAK, expiryTimeOfDay =
> @TimeOfDay)
> 
> public class ErrText implements Serializable {
> 
>                 private static final long serialVersionUID = 5L;
> 
>  
> 
>                 @Id
> 
>                 @Column(name = "ERR_CDE")
> 
>                 private String errorCode;
> 
>  
> 
> However, when I attempt to run the "getErrorText" query, I always
> cache-miss. This data is relatively static, I would like NOT to go to
> the database. I cannot figure out how to hit just the object cache
> without hitting the database:
> 
>  
> 
>                                 Query query =
> em.createNamedQuery("getErrorText");
> 
>                                 query.setParameter("errorCode",
> errText);
> 
>                                 try {
> 
>  
> errTexts.add((ErrText.class), query.getSingleResult());
> 
>                                 } catch (NoResultException e) {
> 
>                                                 System.out.println("NRE:
> " + e.getMessage());
> 
>                                 }
> 
>  
> 
> I also tried using the query cache, which curiously works the first
> time, then triggers NoResultFound the second time...
> 
>  
> 
> Thank you for any help!
> 
>  
> 
> 
> PRIVILEGED AND CONFIDENTIAL
> This email transmission contains privileged and confidential information
> intended only for the use of the individual or entity named above.  If the
> reader of the email is not the intended recipient or the employee or agent
> responsible for delivering it to the intended recipient, you are hereby
> notified that any use, dissemination or copying of this email transmission
> is strictly prohibited by the sender.  If you have received this
> transmission in error, please delete the email and immediately notify the
> sender via the email return address or mailto:postmaster@xxxxxxxxxxxxxxx. 
> Thank you.
> 
> 
> 


-----
http://wiki.eclipse.org/User:James.sutherland.oracle.com James Sutherland 
http://www.eclipse.org/eclipselink/
 EclipseLink ,  http://www.oracle.com/technology/products/ias/toplink/
TopLink 
Wiki:  http://wiki.eclipse.org/EclipseLink EclipseLink , 
http://wiki.oracle.com/page/TopLink TopLink 
Forums:  http://forums.oracle.com/forums/forum.jspa?forumID=48 TopLink , 
http://www.nabble.com/EclipseLink-f26430.html EclipseLink 
Book:  http://en.wikibooks.org/wiki/Java_Persistence Java Persistence 
Blog:  http://java-persistence-performance.blogspot.com/ Java Persistence
Performance 
-- 
View this message in context: http://old.nabble.com/Cannot-get-a-cache-hit-on-entity%21-tp30485223p30605818.html
Sent from the EclipseLink - Users mailing list archive at Nabble.com.



Back to the top