Is any way to remove cache for a specific named query? I don’t really want to remove for all queries… Or is there any other workaround?
It is not working even if I am using the normal Query class…
I am using hibernate 3.6, glassfish 3.1.1, this is an java ee application (code from ejb module)
I have something like this:
public User getUserByName(String username) {
try {
return (User) em.createNamedQuery("User.getUserByName").setParameter("username", username).getSingleResult();
} catch (NoResultException e) {
return null;
}
}
//...
if(getUserByName(entity.getUsername()!=null) {
em.persist(entity);
}
//...
// username added in database (checked)
if(getUserByName(entity.getUsername())==null) {
//something else
}
the second time I use “getUserByName” is again.. null… why?
I am thinking it’s the cache module(because if I set my provider to eclipselink it’s working as it should)…
I am using hibernate for it’s search..
With EclipseLink you can do this:
For hibernate the hint is:
org.hibernate.cacheMode“Override the cache mode for this query ( eg. CacheMode.REFRESH )”For further reading and understanding: old article