Save vs saveOrUpdate vs persist inward Hibernate
What is deviation betwixt save together with saveOrUpdate or Difference betwixt save together with persist are mutual interview enquiry inward whatever Hibernate interview, much similar Difference betwixt larn together with charge method inward Hibernate. Hibernate Session course of education provides twosome of ways to salve object into database past times methods similar save, saveOrUpdate together with persist. You tin role either save(), saveOrUpdate() or persist() based upon your requirement for persisting object into Database. Along amongst Spring framework Interview questions, Hibernate questions are besides quite pop on J2EE interviews because of its condition every bit leading ORM. It’s proficient to laid upward around questions from Hibernate earlier appearing inward whatever J2EE interviews. One of them is Difference betwixt salve , saveOrUpdate together with persist, which nosotros volition encounter inward this Hibernate article.
Difference betwixt salve together with saveOrUpdate inward Hibernate
Main difference betwixt save together with saveOrUpdate method is that save() generates a new identifier together with INSERT tape into database spell saveOrUpdate tin either INSERT or UPDATE based upon being of record. Clearly saveOrUpdate is to a greater extent than flexible inward price of role only it involves an extra processing to discovery out whether tape already exists inward tabular array or not.
In summary save() method saves records into database past times INSERT SQL query, Generates a novel identifier together with render the Serializable identifier back.
On the other mitt saveOrUpdate() method either INSERT or UPDATE based upon being of object inward database. If persistence object already exists inward database together with thus UPDATE SQL volition execute together with if in that place is no corresponding object inward database than INSERT volition run.
In summary save() method saves records into database past times INSERT SQL query, Generates a novel identifier together with render the Serializable identifier back.
On the other mitt saveOrUpdate() method either INSERT or UPDATE based upon being of object inward database. If persistence object already exists inward database together with thus UPDATE SQL volition execute together with if in that place is no corresponding object inward database than INSERT volition run.
Difference betwixt salve together with persist method inward Hibernate
In finally department nosotros saw What are deviation betwixt save together with saveOrUpdate together with at nowadays nosotros volition encounter Difference on save vs persist method.
1)First deviation betwixt salve together with persist is in that place render type. Similar to salve method persist besides INSERT records into database only return type of persist is void spell render type of salve is Serializable object.
2) Another deviation betwixt persist together with salve is that both methods brand a transient event persistent. However, persist() method doesn't guarantee that the identifier value volition endure assigned to the persistent event immediately, the assignment mightiness hap at level time.
3) One to a greater extent than thing which differentiate persist together with salve method inward Hibernate is that is in that place conduct on exterior of transaction boundaries. persist() method guarantees that it volition non execute an INSERT controversy if it is called exterior of transaction boundaries. save() method does non guarantee the same, it returns an identifier, together with if an INSERT has to endure executed to larn the identifier (e.g. "identity" generator), this INSERT happens immediately, no affair if yous are within or exterior of a transaction.
4) Fourth deviation betwixt save together with persist method inward Hibernate is related to previous deviation on salve vs persist. Because of its inward a higher house conduct of persist method exterior transaction boundary, its useful inward long-running conversations amongst an extended Session context. On the other mitt save method is non proficient inward a long-running conversation amongst an extended Session context.
These were around differences betwixt save, saveOrUpdate together with persist method of Hibernate. All 3 method are related to saving Object into database only in that place conduct are quite different. Knowledge of save, persist together with saveOrUpdate non exclusively helps to create upward one's take away heed improve role of Hibernate API only besides assistance yous to create good inward Hibernate interviews.
Further Learning
answer)
Thanks for reading this article, if yous similar this article together with interview enquiry together with thus delight part amongst your friends together with colleagues. If yous accept whatever enquiry or feedback together with thus delight drib a comment.