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

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@xxxxxxxxxxxxxxxx  Thank you.