I know there\'s already a similar question answered previously, but my problem is implementing save with update while there are 3 methods in the interface. I\'m currently us
putting below if check resolve my issue and save method is working as save and update both when i pass id it updates the record in database and when i dont pass id it save new record in database place is incoming object in my case and new place is new object of place in which i am setting the place id
if(place.getPlaceId()!=0)
newPlace.setPlaceId(place.getPlaceId());
CrudRepository
has only save
but it acts as update
as well.
save
on entity with empty id
it will do a save
.save
on entity with existing id
it will do an update
that means that after you used findById
for example and changed something in your object, you can call save
on this object and it will actually do an update
because after findById
you get an object with populated id
that exist in your DB.save
in CrudRepository
can accept a single entity or Iterable
of your entity type.