in Hibernate by
Q:

What is automatic dirty checking in hibernate?

1 Answer

0 votes
by

The automatic dirty checking feature of Hibernate, calls update statement automatically on the objects that are modified in a transaction.

Let's understand it by the example given below:

  1. ...  
  2. SessionFactory factory = cfg.buildSessionFactory();  
  3. Session session1 = factory.openSession();  
  4. Transaction tx=session2.beginTransaction();  
  5.    
  6. Employee e1 = (Employee) session1.get(Employee.class, Integer.valueOf(101));  
  7.    
  8. e1.setSalary(70000);  
  9.    
  10. tx.commit();  
  11. session1.close();  

Here, after getting employee instance e1 and we are changing the state of e1.

After changing the state, we are committing the transaction. In such a case, the state will be updated automatically. This is known as dirty checking in hibernate.


Click here to read more about Hibernate
Click here to read more about Insurance

Related questions

0 votes
asked Jun 8, 2020 in Hibernate by DavidAnderson
0 votes
asked May 27, 2019 in Gradle by Ankita1283
0 votes
asked May 27, 2019 in Gradle by Ankita1283
0 votes
asked May 27, 2019 in Gradle by Ankita1283
0 votes
asked May 27, 2019 in Gradle by Ankita1283
...