~/talk

SQL primary key, surrogate key, composite keys, foreign keys... and JPA

Talkat Joker 2021 · 2021-10-25..10-28· [databases, java]
slides:none on file

Practical rules for keys: use a generated surrogate id for stable joins and JPA object identity, but keep composite keys when the relationship itself is the entity (many‑to‑many) or when multi‑tenant or partitioning needs require parent ids in the child row. Demos run on Yugabyte/Postgres-compatible SQL, show composite foreign keys and an association table without extra id, and map composite keys to an embeddable that must be Serializable and implement equals/hashCode. Prefer sequences with allocationSize and DB cache for scale; UUIDs trade predictability for mergeability.

AI-written summary · about

  1. 0:00Start
  2. 11:02Goal of Adding a Surrogate Key
  3. 23:59Referencing Composite Keys
  4. 36:47Natural Keys
  5. 41:10Composite Keys
  6. 45:40Sequences
~/search
type to search 6,249 conferences, 138,987 speakers and 185,172 talks
~/help
cmdctrl k
search every conference, speaker and series
/
focus the filter search
h
home
c
conferences
s
speakers
e
series
t
light / dark — the status bar button does the same
?
this help
esc
close this, then clear every filter — or just the search, while you are typing in it

Ignored while you are typing. Pages without a filter rail have no search to focus.