SteelReed

Search

Search posts, questions…

JPA & HibernateQuestion 12 / 24

Middle

What inheritance strategies does JPA offer, and how does @MappedSuperclass differ?

Short answer

JPA has three ways to store inheritance: SINGLE_TABLE (one shared table), JOINED (one table per class, joined by primary key), TABLE_PER_CLASS. @MappedSuperclass only shares fields and has no parent table.

no, just share fieldsyesa few columnsa lot, need NOT NULLQuery all kinds at once?@MappedSuperclassSubclasses differ a lot?SINGLE_TABLEJOINED

3 points to say:

  1. SINGLE_TABLE is fastest, but subclass columns must allow null.
  2. JOINED is stricter, but reads need joins.
  3. @MappedSuperclass is only Java inheritance.

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.