SQL, JPA & Hibernate

Where the data lives, and how not to lose it. ACID, isolation levels, joins, indexes, normalization, JPA entity states, lazy loading, the N+1 problem and caching.

Topics in this section

ACID transactions

A bank transfer in a sealed envelope. Atomic: all of it happens or none of it. Consistent: the rules (no negative balances) hold before and after. Isolated: other people's transfers never see yours half-done. Durable: once the bank says “done”, a power cut can't undo it.

Isolation levels & read anomalies

Two people editing one spreadsheet. A dirty read: you see their typing before they hit save. A non-repeatable read: you read a cell twice and it changed in between. A phantom read: you count the rows twice and a new row appeared. Each isolation level blocks one more of these.

Joins, visualised

Two lists: employees and departments. An INNER JOIN keeps only the people matched to a department. A LEFT JOIN keeps every employee and writes NULL where there's no department. RIGHT is the mirror image. FULL keeps everyone from both lists.

Indexes

An index is the index at the back of a textbook. Instead of reading every page to find “Hibernate”, you jump straight to the right pages. Reads get fast — but every new page means updating the index too.

Normalization (1NF → BCNF)

Normalization is tidying a messy spreadsheet so each fact lives in exactly one place. When a customer moves, you change their address once — not in 400 order rows.

SQL essentials & classic queries

SQL has five toolboxes. DDL builds the shelves, DML puts things on them and takes them off, DQL looks at them, DCL hands out keys, and TCL says “save” or “undo”.

Each topic pairs a plain-language explanation with code, interview questions, and related practice where available.