Hi all,
I’m struggling with the query results cache for a particular query. While I got the cache working for another query, this one refuses to work (I see from a SQL trace that there are still queries
executed against the database):
@Entity
@Table(name =
"TRUSTED_ORIGINS")
@TableGenerator(name =
"trustedOriginIdGenerator", table =
"SEQUENCE", pkColumnName =
"NAME", pkColumnValue =
"trusted_origin_id", valueColumnName =
"NEXTID", allocationSize = 1)
@Cacheable
@NamedQueries({
@NamedQuery(name =
"TrustedOrigin.getOriginGroups",
query =
"SELECT DISTINCT(o.groupName) FROM TrustedOrigin o " +
"WHERE (o.account = '*' OR o.account = :account) AND (o.application = '*' OR o.application = :application) AND"
+
"(o.component = '*' OR o.component = :component)",
hints = {
@QueryHint(name = QueryHints.QUERY_RESULTS_CACHE,
value = HintValues.TRUE),
@QueryHint(name = QueryHints.QUERY_RESULTS_CACHE_EXPIRY,
value = "300000")
// 5 minutes
})
})
public
class TrustedOrigin {
@Id
@Column(name =
"ID", nullable =
false)
@GeneratedValue(generator =
"trustedOriginIdGenerator", strategy = GenerationType.TABLE)
private
long
id;
@Basic
@Column(name =
"GROUP_NAME", nullable =
false, length = 100)
private String
groupName;
@Basic
@Column(name =
"ACCOUNT", nullable =
false, length = 30)
private String
account;
@Basic
@Column(name =
"APPLICATION", nullable =
false, length = 30)
private String
application;
@Basic
@Column(name =
"COMPONENT", nullable =
false, length = 30)
private String
component;
@Column(name =
"CREATION_DATE", nullable =
true)
@Temporal(TemporalType.TIMESTAMP)
private Date
creationDate;
// ... constructors, getters and setters
static
List<String> getOriginGroups(EntityManager em, String account, String application, String component) {
return
em.createNamedQuery("TrustedOrigin.getOriginGroups",
String.class)
.setParameter("account",
account).setParameter("application",
application).setParameter("component",
component).getResultList();
}
}
In the persistence.xml, the shared cache is enabled selectively:
<shared-cache-mode>ENABLE_SELECTIVE</shared-cache-mode>
Is there anything wrong with that query? I debugged into the query execution via the getOriginGroups method above, especially to see if it differs from the other query where the results cache works. I found that ReadAllQuery.
execute(AbstractSession session, AbstractRecord row) checks whether the query is prepared (there is even a comment saying “// only prepared queries can have cached results.”) – and this one isn’t. But why? Is it a bug, or am I doing anything wrong?
EclipseLink version is 2.5.1 btw.
Thanks and best regards,
Sabine
Sabine Heider
SAP AG
I Dietmar-Hopp-Allee 16 I 69190 Walldorf I Germany
Pflichtangaben/Mandatory Disclosure Statements:
http://www.sap.com/company/legal/impressum.epx