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

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

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

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.









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.ADS_TO_REPLACE_1 session.persist() : Does the same like 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... - India"); session.save(emp); tr.commit(); System.out.println... of Employee entity, sets the values and finally calls the session.save(emp
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.save(cat); session.flush(); //force the SQL INSERT session.refresh(cat); //re
How to insert data from textfields into database using hibernate?
(IdCantitateTextField); produs.setUnitMas(UnitMasTextField); session.save(produs
getting following error org.hibernate.AnnotationException: No identifier specified for entity: inheritance_tutorial17.TwoWheeler
(); session.save(vehicle); session.save(two); session.save(four
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 : Bulk Insert/Batch Insert
(.....); session.save(student); } tx.commit(); session.close(); By default, Hibernate...++ ) { Student student = new Student (.....); session.save(student); if( i % 50...); session.save(student); if (i % 50 == 0) { session.flush(); session.clear
Hibernate Load Example
"); emp.setEmpMobileNos("000000"); emp.setEmpAddress("Delhi - India"); session.save(emp... and finally calls the session.save(emp)  to save the data. Here... 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 5 native query example
"); session.save(emp1); Employee emp2 = new Employee... - India"); session.save(emp2); tr.commit(); System.out.println
Hibernate persist Method
= scan.next(); employee.setName(setEmpName); session.persist(employee
hibernate pojo setter method problem
(); session.save(e); tx.commit(); session.close(); } }ADS_TO_REPLACE_2 //along
in connectivity - Hibernate
"); contact.setEmail("[email protected]"); session.save(contact
Hibernate Architecture
form the underlying table. When we pass an object to a Session.save
Hibernate Transaction
;Roseindia"); session.save(person); tx.commit(); System.out.println("
Hibernate Many One One Mapping
); session.save(ram); session.save(syam); * * transaction.commit... = new * Student("Syam", address); session.save(ram); session.save(syam
Hibernate Many-to-many Relationships
;session.save(author);            /*  ...;book.setAuthors(authorSet);      session.save(book);  ...);         session.save(author);   
Hibernate saveOrUpdate Method
); person.setType(type); session.saveOrUpdate(person); System.out.println("
Hibernate save or update method example
()); emp.setEmpAddress("New Delhi, India"); session.saveOrUpdate(emp
Hibernate Mapping Many-to-Many Example
student2=new Student("Ric",courses); session.save(student1); session.save(student2); transaction.commit(); }catch
Hibernate - Hibernate
("MCA"); pojo.setState("delhi"); session.save(pojo
fIRST APPLICATION - Hibernate
;); pojo.setState("delhi"); session.save(pojo); tx.commit(); session.flush
hibernate annotations with composite primary key
); studentObject.setId(studentIDObject); session.save
Access data from mysql through struts-hibernate integration
(); // session.save(query); session.close(); saveErrors(request, errors
Writing First Hibernate Code
information to the database: session.save(contact) Here is the code...;session.save(contact);   System.out.println("Done"
How to write hello world example program in Hibernate?
;); session.save(emp); session.getTransaction().commit(); The project structure and jar file...(); emp.setEmpName("Rajesh Koothrapalli"); session.save(emp
Could not read mappings from resource: e1.hbm.xml - Hibernate
"); e1.setPHONE("24332"); e1.setPINCODE("23222"); session.save(e1
Using Hibernate <generator> to generate id incrementally
;Hibernate  Tutorial");   session.save
hibernate annotations
); addressSet.add(a); s.setAddresses(addressSet); session.save(s
Hibernate One To Mapping
", "560000", student); student.setStudentAddress(address); session.save
Hibernate 4 Annotation Example
"); session.save(person); tx.commit(); System.out.println("Done
Hibernate 4 Annotations Tutorial
(); person.setName("Hibernate example"); session.save(person); tx.commit
Hibernate One-to-many Relationships
;group.setStories(list);   // Save group   session.save... session.save(group);ADS_TO_REPLACE_30    
Hibernate Performing the usual DB operations
();    player  player1 = new player(a,b);    session.save..., session.save(palyer1); For updating, player1.setName( player1.setPlace( 

Ads