The solution to code repetition (like for example wiring an
timestamp fields in every Hibernate entity) is to inherit these properties from a superclass. This can be done using the @MappedSuperclass annotation. A mapped superclass designates a class whose mapping information is applied to the entities that inherit from it.
- a mapped superclass has no separate table defined for it;
- mapping information may be overridden in such subclasses by using the @AttributeOverride and @AssociationOverride annotations or corresponding XML elements.
Example: Concrete class as a mapped superclass
Categories & Tags
- HibernateException - A collection with cascade="all-delete-orphan" was no longer referenced by the owning entity instance
- Hibernate - One To Many (Annotation)