What is the difference between save() and persist() methods of session object?



What is the difference between save() and persist() methods of session object?..

Answer / Girja Shankar Vishwakarma

Both save() and persist() methods in Hibernate are used to store Java objects (entities) into the database, but they have subtle differences:
1. Persist(): This method does not automatically flush or synchronize the state of the entity with the database. Instead, it marks the entity as persistent, meaning that its state will be saved when a transaction is flushed or committed.
2. Save(): This method both marks the entity as persistent and flushes the session immediately. So, if you use save(), the entity gets saved directly into the database.

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More Hibernate Interview Questions

What is orm navy?

1 Answers  


Does hibernate work without primary key?

1 Answers  


Is it possible to perform collection mapping with one-to-one and many-to-one?

1 Answers  


What is hql in hadoop?

1 Answers  


Why we use hibernate template?

1 Answers  


Explain some of the elements of hbm.xml?

1 Answers  


How to insert data into database using spring mvc and hibernate?

1 Answers  


How many tables are required for many to many relationship?

1 Answers  


Which settings will be loaded if both hibernate.properties and hibernat.cf.xml files are present in the classpath?

1 Answers  


What is the purpose of orm?

1 Answers  


Define the collection types in hibernate?

1 Answers  


What is l1 and l2 cache in hibernate?

1 Answers  


Categories