title: Evict dependant collections together with parent entity
body: <p>I have just realized that when an object is evicted from Hibernate cache, <a href="http://jaitechwriteups.blogspot.com/2006/08/evict-collection-from-hibernate-second.html" rel="nofollow">dependant collections, if cached, have to be evicted <strong><em>separately</em></strong></a>.</p>
  
  <p>For me this is a one big WTF:</p>
  
  <ul>
  <li>it is really easy to forget to evict a collection (e.g. when a new one is added to the object mapping);</li>
  <li><p>code for evicting dependant collections is ugly and bulky, e.g.</p>
  
  <p><code>MyClass myObject = ...;</code><br/>
  <code>getHibernateTemplate().evict(myObject);</code><br/>
  <code>Cache cache = getHibernateTemplate().getSessionFactory().getCache();</code><br/>
  <code>cache.evictCollection("my.package.MyClass.myCollection1, id);</code><br/>
  <code>...</code><br/>
  <code>cache.evictCollection("my.package.MyClass.myCollectionN, id);</code><br/></p></li>
  </ul>
  
  <p>It is quite obvious that if parent object has changed, there is little sense to keep it's collections around as they are most likely to be derived from that parent anyway.</p>
  
  <p>Am I missing something here? Is there really no way to flush an object together with all its child entities without writing all this code manually?</p>