Online Training Spring Hibernate Training in Delhi R Programming Training Course Big Data and Hadoop Training Java Training  
 

session.save , session.saveOrUpdate, and session.persist

Ads

 
 

Share on Google+Share on Google+

samar
session.save , session.saveOrUpdate, and session.persist
1 Answer(s)      6 years and 5 months ago
Posted in : Hibernate Interview Questions

Difference between session.save() , session.saveOrUpdate() and session.persist()?

Ads
View Answers

March 7, 2011 at 4:58 PM


Hi Samar, 
session.save() : 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 session.save(). 
But session.save() return Serializable object but session.persist() return void. 
         session.save() returns the generated identifier (Serializable object) and session.persist() doesn't.

Ads









Related Tutorials/Questions & Answers:
session.save , session.saveOrUpdate, and session.persist
session.save , session.saveOrUpdate, and session.persist  Difference between session.save() , session.saveOrUpdate() and session.persist
Difference between session.save() , session.saveOrUpdate() and session.persist() in Hibernate
Difference between session.save() , session.saveOrUpdate() and session.persist...() , session.saveOrUpdate() and session.persist()in Hibernate?   session.save... data. session.persist() : Does the same like session.save(). But session.save
Advertisements
Hibernate : Session Save
In this section we will discuss how session.save() works in Hibernate
Hibernate save Example - Rose India Hibernate 4 tutorials
saved the object using the Session.save() method. Here in this section we..."); emp.setEmpAddress("Delhi - India"); session.save(emp); tr.commit... the session.save(emp)  to save the data. Here is the code of the model class
update count from session - Hibernate
update count from session  I need to get the count of how many rows got updated by session.saveOrUpdate(). How would I get this? Thanks, mpr
ramanjaneyulu
ramanjaneyulu  where is the SQL statement in this example? i mean when we call session.save() method it is inserting data into database. where it executes the insert statement. how can i see the insert statement in the code
Hibernate code - Hibernate
Hibernate code  can you show the insert example of Hibernate other than session.save(obj);  Hi I am sending a link where u can find lots of example related to hibernate... http://www.roseindia.net/hibernate
Dirty Checking In Hibernate Example
then the Hibernate will save the object in database if session.save() and other methods... will save the object in database if session.save() and other methods are callled
library
); s2.getCourses().add(c2); session.save(s1); session.save(s2
Hibernate session.refresh() method
. session.refresh() reload all the data. No nned again to select call. session.save(cat
How to insert data from textfields into database using hibernate?
(IdCantitateTextField); produs.setUnitMas(UnitMasTextField); session.save(produs
could not execute native bulk manipulation query
"); } int row = query.executeUpdate(); //session.saveOrUpdate(query
Could not parse configuration: hibernate.cfg.xml
("kamlesh"); session.persist(e1); //persisting the object
Java - Hibernate
("Kumar"); contact.setEmail("[email protected]"); session.save..."); contact.setEmail("[email protected]"); session.save(contact); tr.commit
hibernate code - Hibernate
"); contact.setEmail("[email protected]"); session.save(contact
java(Hibernate) - Hibernate
); System.out.println("user.setPhoneNumbers(s)"); //To Insert record throw { session.save(user); System.out.println("session.save(user)"); tx.commit..."); user.setPhoneNo("9810254612"); session.save(contact); session.save(user
Struts2.2.1 and hibernate integration application
(); session.beginTransaction(); session.save(obInformation
Hibernate Basic Example not working
"); session.save(book); System.out.println("Done"); }catch(Exception e
hibernate firstExample not inserting data - Hibernate
"); session.save(contactBO); System.out.println("After Save"); } catch..."); contact.setEmail("[email protected]"); session.save(contact
Reagrsding Hibernate joins - Hibernate
;); con.setState("bihar"); session.save(con); session.save(contact); tr.commit(); System.out.println("Done"
java
(); session.save(staffing); serealNo = (int)staffing.getSlNo...(); session.save(users); System.out.println("got sl no in registor Dao
Hibernate persist Method
); session.persist(employee); System.out.println("Data has been inserted to the table
Hibernate Load Example
"); session.save(emp); tr.commit(); System.out.println("Successfully inserted..., sets the values and finally calls the session.save(emp)  to save... to use Hibernate's session.save() method to save the data in our example
Problem in running first hibernate program.... - Hibernate
"); session.save(contact); System.out.println("Done"); }catch(Exception...); tx = session.beginTransaction(); session.save(contact
Hibernate saveOrUpdate Method
); session.saveOrUpdate(person); System.out.println("Successfully updated"
Hibernate save or update method example
Delhi, India"); session.saveOrUpdate(emp); tr.commit
hibernate pojo setter method problem
); Transaction tx=session.beginTransaction(); session.save(e
in connectivity - Hibernate
"); contact.setEmail("[email protected]"); session.save(contact
Hibernate Architecture
an object to a Session.save() method, Hibernate reads the state
Hibernate Transaction
;); session.save(person); tx.commit(); System.out.println("Done"