Showing posts with label Hibernate. Show all posts
Showing posts with label Hibernate. Show all posts

Oct 14, 2016

Object states in hibernate: Transient, Persistent and Detached

In hibernate, an object can have 3 states:
  • Transient 
  • Persistent 
  • Detached 

Transient Object

  • When an instance is created for an entity class using new() and has not been saved into the database is called Transient object. 
  • This object has no association with the Session object. 
  • Any modification done to this object does not make any reflections in the database since no row represents this object in the database. 

Apr 13, 2016

Difference between save(), saveOrUpdate() and persist() in Hibernate Session

save()/ saveOrUpdate()/persist(), these methods are present in Hibernates’s Session interface. These methods serves the purpose of moving object’s state from new/transient to persistent state. However there are some differences between these 3 three APIs – one of popular interview question if you are a java developer. This post aims at listing out these differences.