I know that Session.save()
persists the transient object. And I see that it also has saveOrUpdate()
, and also persist()
.
I suppose then that save()
is equivalent to SQL INCLUDE
, is it?
If I have an object that already exists on DB and I save()
it, will another row be included, will its fields be updated, or will it just be ignored and nothing happen?
Hibernate save method returns the generated id immediately, this is possible because primary object is saved as soon as save method is invoked. If there are other objects mapped from the primary object, they gets saved at the time of committing transaction or when we flush the session.
save() method is executed whenever an instance of a particular model is created either from admin interface or shell, save() method is run. You can override save() function before storing the data in the database to add new data or remove some data to be stored in a database.
Difference between save and saveOrUpdate in Hibernatesave() generates a new identifier and INSERT record into the database while saveOrUpdate can either INSERT or UPDATE based upon the existence of a record.
Difference between saving and persist method in Hibernate 1)The first difference between save and persist is there return type. Similar to save method, persist also INSERT records into the database, but return type of persist is void while return type of save is Serializable Object.
Difference between save
and saveOrUpdate
Main difference between save
and saveOrUpdate
method is that save
generates a new identifier and INSERT
record into database while saveOrUpdate
can either INSERT
or UPDATE based upon existence of record. So save
will proceed without performing existence check, on the other hand saveOrUpdate
will check for existence, if record exists it will be updated else a new record will be inserted.
Basic differences between persist
and save
1)First difference between save
and persist
is their return
type. Similar to save
method, persist
also INSERT
records into database but return type of persist
is void
while return type of save
is Serializable object
.
2) Another difference between persist
and save
is that both methods make a transient instance persistent. However, persist
method doesn't guarantee that the identifier value will be assigned to the persistent instance immediately, the assignment might happen at flush time.
save Persists an entity. Will assign an identifier if one doesn't exist. If one does, it's essentially doing an update. Returns the generated ID of the entity.
I'm suggesting, You really need to read this for proceeding further.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With