Hibernate Cache with select Count

Asked

Viewed 61 times

3

Hello!

I have a JPQL consultation, with count:

public Long quantidadeFaturasAbertasAssinante(Integer idAssin){     
   return manager.createQuery("select count(f) from Fatura f where f.dataLiquidacao IS NULL and f.assinante.id = :ass", Long.class)
            .setParameter("ass", idAssin)                
            .getSingleResult();    

}

When running the first time after starting Tomcat brings the correct value. So I change some direct settlement date at the bank, but the value always stays the same until I reset Tomcat.

It’s like it’s cached, but I’ve cleared the Hibernate cache and it doesn’t change. Any idea?

I’m using version 4.3.8 of Hibernate, I’ve tried switching to 4.3.11 and it’s no use. I’m using with JSF primefaces and CDI.

  • You have activated the Hibernate query cache (http://docs.jboss.org/hibernate/core3.3/reference/en/html/performance.html#performance-querycache)?

1 answer

0

A possible answer to your problem is whether the Query Cache is activated:

hibernate.cache.use_query_cache = true

This configuration creates a cache using String of the query and the parameters passed. Thus, when these two pieces of information match what is already in the cache, Hibernate returns the ready result directly from the cache, without consulting the database.

This would explain why your database changes do not reflect in the application.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.