Why ? - Second level cache should be set to false for batch updates is this true

501 views Asked by At

Hibernate documentation says second level cache should be set to false for batch updates is this true , if so why ? both are true is any problem ? org.hibernate.cache.ehcache.EhCacheRegionFactory true 50

1

There are 1 answers

2
Aaron Digulla On

The second level cache keeps a reference to all objects which are used in the current transaction. Batch updates are mostly used to update many objects (> 10'000). That many objects need a lot of memory but for little gain: You probably don't need any of them again, soon (or rather, if you update a million objects, you don't really know which one of them you'll need next).

So putting all these objects in the second level cache poses two problems: 1. It wastes memory and 2. it can allocate so much memory that you run out of it.

To disable the cache for the current session, use session.setCacheMode(CacheMode.IGNORE). Source: https://forum.hibernate.org/viewtopic.php?f=1&t=964775