| Key |
save() |
persist() |
| Basic |
It keeps track of objects in a database. |
It also keeps track of objects in a database. |
| Return type |
The save () method's return type is a serializable object. |
The persist () method has a void return type. |
| Transaction Boundaries |
It can save objects both within and outside of boundaries. |
It can only save objects that are within the transaction's boundaries. |
| Assigning of identifier value |
The save() method enables the quick assignment of an identifier value. |
The persist() method does not promptly ensure that an identifier value is assigned to a persistent state. |
| Detached Object |
For detached objects, it will add a new row to the table. |
For detached objects, it will throw a persistence exception. |
| Execution of insert query |
The save() method returns an identifier intending to execute an insert query immediately to get the identification. It makes no difference whether the transaction is outside or inside. |
If an insert query is placed outside the transaction boundaries, the persist() method fails to perform it. |
| Supported by |
Hibernate is the only framework that supports it. |
JPA is also in support of it. |
| Utility |
The save approach is less useful in a long-running conversation that has expanded a Session context. |
The persist method is used in long-running discussions that provide an extended Session context since it is called outside transaction boundaries. |