Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I encountered the same problem. And I tried 4 ways to walk around this problem. All work.</p> <pre><code> 1. change merge(User) to saveOrUpdate(User) 2. After merge, call session.clear() 3. Use a new session for the second merge 4. User = merge(User) </code></pre> <hr> <p>Then I did some research wondering what make these solutions possible. Note the 2nd solution. According to <a href="https://stackoverflow.com/questions/8118436/org-hibernate-session-clear-considered-harmful">org.hibernate.Session.clear() considered Harmful?</a> <code>clear</code> clears the L1 cache. So I believe after you merge, somehow data is still stored in cache. <code>Clear</code> will detach all the objects associated with this session.</p> <p>Note 1st solution. According to this <a href="https://stackoverflow.com/questions/5311928/hibernate-envers-merge-saveorupdate">hibernate envers: merge &amp; saveOrUpdate</a> difference between <code>saveOrUpdate</code> and <code>merge</code> is that <code>saveOrUpdate</code> makes the object persistent, whereas <code>merge</code> return the persistent object. When you merge again, since the argument is not persistent, hibernate uses the cache to load object from db. This results in the strange query. </p> <p>So I came to the 4th solution. This makes your user the attached object. Then when you merge again, it is merging the persistent object. Hibernate doesn't query db this time.</p> <p>As for the 3rd solution. It came from a trial.</p> <p>These are my understanding for this question. Not sure if it's accurate. But I hope this helps. To be safe, I recommend you use <code>solution 1</code>, and <code>solution 4</code>.</p>
    singulars
    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.
    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