0 votes
in Hibernate by
edited by
What is automatic dirty checking in hibernate?

2 Answers

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.


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:

...  

SessionFactory factory = cfg.buildSessionFactory();  

Session session1 = factory.openSession();  

Transaction tx=session2.beginTransaction();  

   

Employee e1 = (Employee) session1.get(Employee.class, Integer.valueOf(101));  

   

e1.setSalary(70000);  

   

tx.commit();  

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.

Related questions

0 votes
asked Jun 8, 2020 in Hibernate by DavidAnderson
0 votes
asked Jan 1 in Hibernate by rajeshsharma
...