Problem with Spring Boot JPA

Ashutosh Kumar
1 min readJul 22, 2021

--

Stupid implementation of the deleteAll() method

The server showed a great latency issue while running deleteAll operation with Spring Boot JPA -> Service becomes unresponsive.

The spring boot JPA uses a SELECT * in its deleteAll method as the default implementation. It was reading all rows and then executing the delete method on all of them individually.
Couldn’t a simple implementation of the “delete from [table name]” have sufficed?

At a high scale, It’s better to write your own queries with hibernate.

JPA is good for quick/fast development but if you are building for scale better not use it. (gradually I learned that why in my first company, they had written custom queries everywhere, the developer has better control over there). If you are updating rows in a highly normalized database with JPA, it will select all connected rows and then update, You will only realize these issues while debugging a production issue.

--

--

Ashutosh Kumar
Ashutosh Kumar

Written by Ashutosh Kumar

Backend Engineering | BIT Mesra | Building Microservices and Scalable Apps | Mentor

Responses (3)