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?
2 Answers
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) } 1 Comment
Syed Mohammed Mehdi
I have multiple records in that table for that Id and need to update multiple records of it, for this how to handle please? because above is not working for this?
if(repo.existsById(id)){ //code for update repo.save(entity) } 4 Comments
Syed Mohammed Mehdi
I have multiple records in that table for that Id and need to update multiple records of it, for this how to handle please? because above is not working for this?
Zorglube
For that kind of problem I think you'll have to make some
SQL/JPQL/HQL or something. You'll probably end by running something like Update Into ... Set value=XX Where id=YYY.Syed Mohammed Mehdi
in custom update query can we pass class also? I have 50 columns to update so i keep all those 50 columns in one class C1 apart from ID so UPDATE SET C1=:C1CLASS WHERE ID=:IDCLASS....is this possible ?
Zorglube
Not sure but probably.