Storing data into DataBase using Hibernate

To store data into Database using Hibernate Framework we use the following three methods.
  1. save
  2. persist
  3. save or update
save() : This method is used to store the data in Database. When we use save() method, it generates a new identifier and INSERT record into the database using INSERT query. It generates a new identifier and returns the Serializable identifier back. The following is the syntax of save() method.
  • serializable save(Object object)
persist() : This method is also used for storing the data in the DataBase.This method is same as the save(). But this method does not returns a value. The following is the syntax of persist() method.
  • void persist(Object object)
saveorupdate() : This method also used to store the data into the database. When we use this method it checks for the record, if the record exists it just updates the record. If the record is not exist then it inserts a new record.

The following is the Hibernate application which inserts the data into Database. Here we are using save().

Program to Insert values into database using Hibernate
Program to Insert values into database using Hibernate

                                              

1 comment: