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!