Skip to main content

Posts

Spring Boot JPA Entities, Flyway Migrations & Spring Data Repositories — The Database Layer Done Right (Episode 5)

There is one line in almost every Spring Boot tutorial that runs flawlessly on your laptop and slowly corrupts your database in production: spring : jpa : hibernate : ddl-auto : update # works on your laptop, quietly rewrites prod With ddl-auto: update , Hibernate looks at your entities on every startup and alters the live schema to match them. No migration file. No version. No review. No rollback. Two developers add different fields, deploy in a different order, and now staging and production have quietly diverged — and the day one of those "updates" needs to drop a column, Hibernate will happily take your data with it. In Episode 5 of Building Instagram's Authentication Backend , we do the opposite. The database is not something Hibernate improvises at boot — it is a versioned artifact, checked into git, owned by Flyway . We build the persistence layer in three deliberate steps: the SQL migration , then the JPA entities , then the Spring Data r...
Recent posts

Spring Boot DTOs and Validation: A Complete Guide

There is one line of code that quietly ruins more Spring Boot APIs than any other: return userRepository.findById(id).orElseThrow(); It compiles. It returns 200 OK. It ships. And it hands the entire internet your BCrypt password hash, your account-lock state, and your failed-login counter — because Jackson serialises every field it can reach, and your @Entity was never designed to be read by strangers. In Episode 4 of Building Instagram's Authentication Backend , we build the wall that stops this: DTOs . Ten of them, in one file, guarding nine endpoints. This article is the written companion — every annotation, every design decision, and the exact reason request DTOs and response DTOs are not the same kind of object. What you'll build One file — dto/AuthDtos.java — containing 7 request DTOs (validated input) and 3 response DTOs (controlled output), wired to the GlobalExceptionHandler we built in Episode 3. What Is a DTO in Spring Boot? A DTO (Data Transfer ...