Automatically discard request cache

I am trying to understand how hibernate query cache works. Now I see that Hibernate does not automatically update its second level cache when inserting new objects into the database (although I only use Hibernate calls). The only way I found work was to manually clear the cache after inserting new objects.

Here is a more specific example. I have a persistent object called Container that can have many elements. I wanted all elements to be cached:

@Cache (usage = CacheConcurrencyStrategy.READ_WRITE)
class Item 
{
  // rest of the code ...
}

class Container {
  @Cache (usage = CacheConcurrencyStrategy.READ_WRITE)
public List getItems () {...} // rest of the code ... }

The problem I noticed is that when I:

1) db ( )

   String hql =
      "from Container c left join fetch c.items where c.type = 1";
   List<Item> list = hibernateTemplate.find(hql);

2)

   hibernateTemplate.save(item)

3)
, . , :

   sessionFactory.evictCollection("Container.items", updatedContainerId)

, Hibernate . - , ? - ?

.

+3
3

Hibernate , ( ) . , , .

, SessionFactory.evictQueries.

+1

, SQL-. HQL- , - , , INSERT/UPDATE/DELETE .

, Hibernate Dynamic SQL Cache, SQL- .

P.S. " " :)

-1
source

Source: https://habr.com/ru/post/1697804/


All Articles