|Home |Login |Registration |Struts Step by Step Tutorial |Hibernate Step by Step Tutorial |Spring Step by Step Tutorial |JSP Step by Step Tutorial |JDBC Step by Step Tutorial |Web Services Step by Step Tutorial |EJB fundamentals | ORACLE Step by Step Tutorial | SCJP 5.0 and SCJP 6.0 Study Guide | SCWCD 5.0 Study Guide | SCJP Tips
Java mock test | SCJP mock test | SCJP DUMP | SCBCD mock test |Java online test exam | JSP online test | ORACLE online test | Hibernate online test | Servlet online test | Struts online test | EJB online test | C online test | C++ online test | Aptitude online test

Java interview questions | JSP interview questions | ORACLE interview questions | Hibernate interview questions | Servlet interview questions | Struts interview questions | JDBC interview questions | C/C++ interview questions | Spring interview questions | JMS interview questions | Informatica interview questions | EJB interview questions | OOPS and Design Pattern interview questions
1600 PMP mock questions 1400 CAPM mock questions 800 SCJP 6 mock questions 600 OCAJP 7 mock questions 590 OCPJP 7 mock questions 556 SCWCD 5 mock questions 500 OCEJWCD 6 mock questions pdfDownload (java,struts, hibernet etc) JobsJobs and Walkins

 

Recent Questions

!!! Hibernate Frequently Asked Questions !!!

Q.Difference between session.update() and session.lock() in Hibernate ?

SCJP 1.5/1.6 Exam Kit

!!!Answer!!!- From Technical Expert

Both of these methods and saveOrUpdate() method are intended for reattaching a detached object.
The session.lock() method simply reattaches the object to the session without checking or updating the database on the assumption that the database in sync with the detached object.
It is the best practice to use either session.update(..) or session.saveOrUpdate().
Use session.lock() only if you are absolutely sure that the
detached object is in sync with your detached object or if it does not matter because
you will be overwriting all the columns that would have changed later on within the same transaction.

Each interaction with the persistent store occurs in a new Session. However, the same persistent instances are reused for each interaction with the database. The application manipulates the state of detached instances originally loaded in another Session and then "reassociates" them using Session.update() or Session.saveOrUpdate().

// foo is an instance loaded by a previous Session
foo.setProperty("bar");
session = factory.openSession();
session.saveOrUpdate(foo);
session.flush();
session.connection().commit();
session.close();
You may also call lock() instead of update() and use LockMode.READ (performing a version check, bypassing all caches) if you are sure that the object has not been modified.

Answered By : null Replied Date : Apr 10 2012
Answer :


Answered By : null Replied Date : Mar 30 2012
Answer :


Answered By : null Replied Date : Feb 25 2012
Answer :


Answered By : null Replied Date : Feb 22 2012
Answer :


Answered By : null Replied Date : Jan 23 2012
Answer :


Answered By : null Replied Date : Jan 13 2012
Answer :


Answered By : null Replied Date : Jan 11 2012
Answer :


Answered By : null Replied Date : Jan 3 2012
Answer :


Answered By : null Replied Date : Jan 2 2012
Answer :


Answered By : null Replied Date : Nov 19 2011
Answer :


Answered By : null Replied Date : Nov 6 2011
Answer :


Answered By : null Replied Date : Oct 27 2011
Answer :


Answered By : null Replied Date : Oct 13 2011
Answer :


Answered By : null Replied Date : Sep 25 2011
Answer :


Answered By : null Replied Date : Sep 25 2011
Answer :


Answered By : null Replied Date : Jul 16 2011
Answer :


Answered By : null Replied Date : Jul 8 2011
Answer :


Answered By : null Replied Date : Jun 20 2011
Answer :


Answered By : null Replied Date : Jun 17 2011
Answer :


Answered By : null Replied Date : Jun 10 2011
Answer :


Answered By : null Replied Date : Apr 19 2011
Answer :


Answered By : null Replied Date : Apr 6 2011
Answer :


Answered By : null Replied Date : Mar 21 2011
Answer :


Answered By : null Replied Date : Mar 9 2011
Answer :


Answered By : null Replied Date : Mar 6 2011
Answer :


Answered By : null Replied Date : Feb 28 2011
Answer :


Answered By : null Replied Date : Feb 25 2011
Answer :


Answered By : null Replied Date : Feb 21 2011
Answer :


Answered By : null Replied Date : Feb 20 2011
Answer :


Answered By : null Replied Date : Feb 18 2011
Answer :


Answered By : null Replied Date : Feb 15 2011
Answer :


Answered By : null Replied Date : Feb 8 2011
Answer :


Answered By : null Replied Date : Feb 7 2011
Answer :


Answered By : null Replied Date : Feb 6 2011
Answer :


Answered By : null Replied Date : Jan 29 2011
Answer :


Answered By : null Replied Date : Jan 15 2011
Answer :


Answered By : null Replied Date : Dec 30 2010
Answer :


Answered By : null Replied Date : Dec 29 2010
Answer :


Answered By : null Replied Date : Dec 28 2010
Answer :


Answered By : null Replied Date : Dec 17 2010
Answer :


Answered By : null Replied Date : Dec 4 2010
Answer :


Answered By : null Replied Date : Nov 26 2010
Answer :


Answered By : null Replied Date : Nov 20 2010
Answer :


Answered By : null Replied Date : Nov 7 2010
Answer :


Answered By : null Replied Date : Nov 7 2010
Answer :


Answered By : null Replied Date : Nov 7 2010
Answer :


Answered By : null Replied Date : Nov 7 2010
Answer :


Answered By : null Replied Date : Nov 7 2010
Answer :


Answered By : null Replied Date : Nov 7 2010
Answer :


Answered By : null Replied Date : Sep 18 2010
Answer :


Answered By : null Replied Date : Sep 5 2010
Answer :


Answered By : null Replied Date : Aug 21 2010
Answer :


Answered By : null Replied Date : Aug 16 2010
Answer :


Answered By : null Replied Date : May 8 2012
Answer :


Answered By : null Replied Date : May 23 2012
Answer :


Answered By : null Replied Date : Jun 3 2012
Answer :


Answered By : null Replied Date : Jul 9 2012
Answer :


Answered By : null Replied Date : Jul 19 2012
Answer :


Answered By : null Replied Date : Aug 1 2012
Answer :


Answered By : null Replied Date : Aug 20 2012
Answer :


Answered By : null Replied Date : Aug 31 2012
Answer :


Answered By : null Replied Date : Sep 2 2012
Answer :


Answered By : null Replied Date : Sep 8 2012
Answer :


Answered By : null Replied Date : Oct 10 2012
Answer :


Answered By : null Replied Date : Nov 2 2012
Answer :


Answered By : null Replied Date : Nov 3 2012
Answer :


Answered By : null Replied Date : Nov 5 2012
Answer :


Answered By : null Replied Date : Nov 16 2012
Answer :


Answered By : null Replied Date : Dec 26 2012
Answer :


Answered By : null Replied Date : Jan 9 2013
Answer :


Answered By : null Replied Date : Jan 15 2013
Answer :


Answered By : null Replied Date : Jan 15 2013
Answer :


Answered By : null Replied Date : Feb 20 2013
Answer :


Answered By : null Replied Date : Feb 20 2013
Answer :


Answered By : null Replied Date : Mar 14 2013
Answer :


Answered By : null Replied Date : Apr 16 2013
Answer :


 

You can also contribute to this answer:

Your Name:
Answer:

 
Ask Question and get answer from Expert.
View Answers List from Expert.

The information you are posting should be related to java and ORACLE technology. Not political.