Ditching Raw SQL for Spring Data JPA

Day 23. I stopped writing raw SQL in my repositories. Not because SQL is bad. Because Spring Data JPA was already doing it for me. And I didn’t know. I used to write this: @Query("SELECT * FROM users WHERE email = :email", nativeQuery = true) User findByEmail(@Param("email") String email); It worked. Until I realized I was solving a problem the framework had already solved. Here’s what actually happens: → Queries tied directly to database structure → Harder to refactor when schema changes → Less readable for other developers → You bypass what Spring Data JPA already gives you That’s not flexibility. That’s unnecessary complexity. So I changed it. (see implementation below 👇) User findByEmail(String email); No SQL. Same result. Better readability. Now: → Let JPA generate simple queries → Use @Query only when needed → Native SQL only for edge cases The hard truth: → Writing SQL feels powerful → But overusing it makes your code rigid → Most queries don’t need it Using SQL is easy. Knowing when NOT to use it is what makes you a backend developer. Are you still writing SQL for simple queries? 👇 Drop it below #SpringBoot #Java #JPA #BackendDevelopment #JavaDeveloper

  • text

Hot take: If you're writing native SQL for basic queriesin a Spring Boot app — you're working against the framework. Spring Data JPA naming conventions exist for a reason. findByEmail() → SELECT * FROM users WHERE email = ?findByAgeGreaterThan() → SELECT * FROM users WHERE age > ? The framework writes the query.You write the intent. Are you using derived query methods? 👇

Like
Reply

To view or add a comment, sign in

Explore content categories