Syed Mohammed Mehdi
Syed Mohammed Mehdi

Reputation: 313

Jpa only Update in Table and not Insert

I have requirement to only update in table and not insert or select in that table. If a record is present then update or else ignore. How to please implement this using JPA?

Upvotes: 0

Views: 375

Answers (2)

Zorglube
Zorglube

Reputation: 734

if(repo.existsById(id)){
    //code for update
     repo.save(entity)
}

Upvotes: 1

Gaurav Dhiman
Gaurav Dhiman

Reputation: 1023

First of all do findById(), if entity is returnted for that id, then you can go for update otherwise you can skip

UserEntity entity=repo.findById(1111);
if(null!=entity){
    //code for update
     repo.save(entity)
 }

Upvotes: 1

Related Questions