Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Once you load the data from the db, it becomes persistent, and any changes made to it will be updated, if it is updated before the session is closed. If you do not want the data in the db to be updated with the changes you are making after loading it, make the changes only after closing the session. Then after that, if you want to persist the data again, open one more session and call save() or persist(). </p> <p>EDIT: 1) Make sure cache is disabled in order to ensure there is no caching between different sessions.</p> <pre><code>&lt;property name="cache.provider_class"&gt;org.hibernate.cache.NoCacheProvider&lt;/property&gt; </code></pre> <p>2) Follow the steps:</p> <p>i) begin session --> begin transaction --> get data from both tables --> close transaction --> close session.</p> <p>ii) create object of 3rd table--> do whatever u want with it, like adding data from the first two tables.</p> <p>iii) begin new session --> begin new transaction --> save the object of 3rd table using session.save() --> close transaction --> close session.</p> <p>After step (i) is done, the objects from table1 and table2 are no more 'persistent', and are 'detached'. If you don't do session.save() in step (iii), the object of table3 won't get saved, because it is no longer dealing with persistent objects.</p> <p>This is from my understanding of persistent and detached objects. If it doesn't work, do reply. I will code it down and find a solution.</p> <p>And one more advice, do consider using session.persist() instead of session.save(). If you want to understand their difference, this is the link: <a href="https://stackoverflow.com/questions/5862680/whats-the-advantage-of-persist-vs-save-in-hibernate">What&#39;s the advantage of persist() vs save() in Hibernate?</a></p> <p>Good Luck!</p>
 

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