@MappedSuperclass — Concept Check
Questions on @MappedSuperclass. @MappedSuperclass shares fields across entities without creating a table; ideal for audit fields (createdAt, updatedAt, createdBy) that appear in every entity.
Questions in this quiz
7 questions on @MappedSuperclass — Concept Check. Work through them here, then start the quiz to answer them and see your score.
1.A developer wants to share common audit fields across multiple entities without creating a separate table for them. Which JPA annotation should they use?
- A@Entity
- B@Table
- C@Inheritance
- D@MappedSuperclass
2.You have a base class annotated with @MappedSuperclass and several entity subclasses. What happens when you try to query the base class directly?
- AThe query returns an empty result set
- BA table is created for the base class
- CAn exception is thrown
- DA polymorphic query is executed
3.A developer mistakenly believes @MappedSuperclass can be used for polymorphic queries. What is the correct approach for polymorphic queries in JPA?
- AUse @Inheritance with SINGLE_TABLE strategy
- BUse @Entity with @Table
- CUse @IdClass for polymorphism
- DUse @MappedSuperclass
4.A developer uses @MappedSuperclass for audit fields but notices they aren't populated automatically. What might be missing?
- AEntityListeners setup
- B@Inheritance annotation
- C@Id annotation
- D@Table annotation
5.During a code review, you see a @MappedSuperclass with setters for audit fields. What should you do?
- ARemove setters for audit fields
- BConvert to @Entity
- CAdd @Table annotation
- DAdd more fields
6.What is the primary advantage of using @MappedSuperclass for audit fields in a JPA application?
- AEnables direct querying of the superclass
- BCentralizes common fields without a separate table
- CAutomatically generates unique constraints
- DAllows polymorphic queries
7.A developer wants to automatically populate createdBy and updatedBy fields in their entities. Which setup is necessary?
- AEnable Spring Data auditing and provide an AuditorAware bean
- BAnnotate fields with @Id
- CUse @Table annotation
- DImplement @Inheritance strategy