The id is defined once for the whole hierarchy and is inherited, so the @Id
attribute in the Vehicle
class is enough.
@MappedSuperclass
means that the class is not mapped to a separate table, but rather is part of it's children's tables. If you want a normalized schema, make Vehicle
an entity as well.
You do not need to define foreign keys for child entities. This is done by the persistence provider and can be transparent to the developer.
Please note that JOINED
inheritance strategy is less performant than the default SINGLE_TABLE
strategy. SINGLE_TABLE
requires more space and does not really support non-nullable columns for derived entities.