ContactUs

Please send your Questions & Answers or Feedback to "mohan@javabook.org"

What are evict and replicate methods ?

evict : It changes persistance state object to detached state,removes this instance from the session cache.Changes will not be synchronized with the DB.
note : if the object is in persistance state then only it will synchronise with the DB, transient and detatched object will not be sync with the DB.
        Student student = (Student)session.get(Student.class,"1"); ==> P
        student.setStudentName("N@IT - U");
here the student is in persistance state,so no need to call update...while executing the transaction.commt(),it will sync with the DB.
    In jdbc it will not happen like this.....
    JDBC code ==
        while(rs.next()) {
            =====
            student.setStudentName(rs.getString("SNAME"));
            }
        if we modify student.setStudentName("N@It - U");
        this value it will not sync with the DB...
        we need to call the update query then only it will sync but in hibernate its automatic.....
       
    Student = (Student)session.get(Student.class,"1"); -P
    session.evict(student);    - D
    session.replicate(student,ReplicationMode.LATEST_VERSION);    - P
    student.setStudentName("N@It - U");
   
 
1.if evict/replicate both are in comment then it will update the record because it in Persistance state.
2.if evict is not in comment and replicate in comment..then record will not sync because its in detatched state.
3.if both are not in comment then also record will update,because its first changed to detatched then changed to persistance...so it will sync...
        note : we are passing ReplicationMode and its for to take the latest version of the object...
Related Posts Plugin for WordPress, Blogger...
Flag Counter