Latest Tutorials| Questions and Answers|Ask Questions?|Site Map

Home Answers Viewqa Hibernate Difference between , session.saveOrUpdate() and session.persist() in Hibernate

View Questions and Answers by Category


Have Programming Question? Ask it here!

Rahul Dev
Difference between , session.saveOrUpdate() and session.persist() in Hibernate
1 Answer(s)      3 years and 11 months ago
Posted in : Hibernate

What is difference between , session.saveOrUpdate() and session.persist()in Hibernate?

View Answers

October 26, 2010 at 3:55 PM : Save does an insert and will fail if the primary key is already persistent.

session.saveOrUpdate() : saveOrUpdate does a select first to determine if it needs to do an insert or an update. Insert data if primary key not exist otherwise update data.

session.persist() : Does the same like But return Serializable object but session.persist() return void. returns the generated identifier (Serializable object) and session.persist() doesn't. For Example : if you do :- System.out.println(; This will print the generated primary key. if you do :- System.out.println(session.persist(question)); Compile time error because session.persist() return void.

Related Tutorials/Questions & Answers: