Posts

Showing posts with the label Automatic dirty checking

Automatic Dirty Checking in Hibernate

Hibernate provides as feature called Automatic Dirty checking whereby changes to a persistent object are automatically saved to the database when the session is flushed or the transaction is committed. So the code does not need to invoke an explicit save or update. In this article, I will be covering this feature in detail. Introduction Hibernate supports 3 entity states, transient, persistent and detached. In order to understand more about entity states, you can refer to this article. So basically, an object can move into the persistent state when any one of the following happens: When the code invokes session.save, session.persist or session.saveorUpdate When the code invokes session.load or session.get Any changes to a persistent object are automatically saved to the database when the session in flushed. Flushing  is the process of synchronizing the underlying database with the objects in the session. There is a session.flush method available but you generally don’t need to invoke ...