0

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 2

1

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) } 
Sign up to request clarification or add additional context in comments.

1 Comment

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?
1
if(repo.existsById(id)){ //code for update repo.save(entity) } 

4 Comments

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?
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.
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 ?
Not sure but probably.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.