save vs persist Hibernate

Save():

1. Syntax: public Serializable save(Object object) throws HibernateException. 2. The return type of the save method is java.io.Serializable. It returns the generated Id after saving the record. 3. It can save the changes to the database outside of the transaction. i.e. Save method can be used inside or outside the transaction. 4. Session.save() for a detached object will create a new row in the table. 5. Save method takes more time to execute.

Persist():

1. Syntax: public void persist(Object object) throws HibernateException. 2. It does not returns generated Id after saving. Its return type is void. 3. Persist method can be used only within the transaction. 4. session.persist() for a detached object will throw PersistentObjectException as it is not allowed. 5. Persist method takes less time to execute.

Please follow and like us:
Content Protection by DMCA.com