Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>Ad. A</strong>: Looks like you are aware what <code>clear()</code> does. The reason to call it explicitly is to remove all managed entities from L1 cache, so that it does not grow infinitely when processing large data sets in one transaction.</p> <p>It discards all the changes that were made to managed entites <strong>not explicitly persisted</strong>. This means that you can safely modify an entity, update it explicitly and clear the session. This is the <em>right</em> design. Obviously if no changes are made (long, but read only session), <code>clear()</code> is always safe.</p> <p>You can also use <a href="http://docs.jboss.org/hibernate/core/3.3/reference/en/html/batch.html" rel="noreferrer">stateless sessions</a>.</p> <p><strong>Ad. B</strong>: No, it exists for the reasons above: to make sure L1 (session cache) does not grow too much. Of course maintaining it manually is a poor idea and an indication that another tool should be used for large data sets, but sometimes it is a must.</p> <p>Note that in JPA specification there is also <code>clear()</code> and <code>flush()</code> method. In this case you should always call <code>flush()</code> first to push changes into the database (explicit update) prior to calling <code>clear()</code>.</p> <p><strong>Ad. C</strong>: It's actually a good idea to warn the user (maybe by issuing warning message rather than throwing an exception) when he/she clears the session with dirty changes. Also I don't think a <em>framework</em> code should call <code>clear()</code> unconditionally, unless it is sure that the user code it runs flushes or does not make any changes.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload