If Java already validates input, do you still need NOT NULL, CHECK, FK and UNIQUE in the database?
Short answer
Yes. Java validation protects one entry point; database constraints protect every entry point and are the only thing that stops two concurrent requests from both writing.
3 points to say:
- Java gives friendly errors; the DB enforces the real rule.
- Check-then-insert breaks under concurrency.
CASCADEonly within one unit of data.
Keep reading the deep dive
Create a free account to read the full explanation and follow-up questions, mark questions as studied and review them on a schedule.