0

I am using spring-data-jpa to perform delete operation.

Currently, I have a query like:

@Modifying
@Transactional
@Query("Delete from student s where(:studentName is null Or s.studentName =:studentName) and s.studentId IN(:studentIds)")
int deleteByStudentIdAndRollNo(@Param("studentName") String studentName, @Param("studentIds") List<Integer> studentIds)

The above query is working fine and is returning a count of successfully deleted rows from the table.
But the problem is, now I have to return deleted List<Students> instead of the number of deleted records.


I am aware of the fact that @Query will always return the count of successfully deleted records.

I tried to use deleteBy like below:

List<Student> deleteByStudentIdStudentNameIsNullOrStudentNameIsAndStudentIdIN , But that's not working.
Is there any way to get list of deleted students?

1 Answer 1

1

This article show how to return deleted records: Spring Data JPA – Derived Delete Methods

And try maybe this code:

List<Student> deleteAllByStudentNameIsNullOrStudentNameAndStudentIdIn(String studentName, List<Integer> studentIds);

But can't be sure that will be work because I don't know your Student's model structure.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks, it worked. Could you please share a reference document, so that I can also learn?
What document? What do you mean?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.