how to automatically refresh a cached namedquery after object insertion/deletion ? [message #696990] |
Fri, 15 July 2011 09:21 |
Sebastian Messages: 2 Registered: July 2011 |
Junior Member |
|
|
Hi All,
I have a cached namedquery
@NamedQuery(name = "CoverholderAgreement.all",
query = "SELECT c FROM CoverholderAgreement c",
hints = {
@QueryHint(name = QueryHints. QUERY_RESULTS_CACHE, value=HintValues.TRUE)
})
which speed up my code significantly... (so far so good)
in some part of the application I add and delete objects... doing that, the namedquery cache is not automatically refreshed so I need to refresh it by hand at every occation that I modify the DB:
Quote:
utx.commit();
((JpaEntityManager)em.getDelegate()).getServerSession().getIdentityMapAccessor().clearQueryCache("CoverholderAgreement.all");
I do not like this option as it leads to generate new bugs... think about the case when I persist another object which by CASCADING persists a new CoverholderAgreement and I forget to refresh the namedquery cache... (this things hapends specially after some time or when future developers maintain the code and they are not aware of some cached namedquery)...
so just wondering if there is a better way for doing it ????
thanks !
[Updated on: Fri, 15 July 2011 09:22] Report message to a moderator
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.02795 seconds