background image

Mapped Superclasses

<< Unidirectional Relationships | Entity Inheritance Mapping Strategies >>
<< Unidirectional Relationships | Entity Inheritance Mapping Strategies >>

Mapped Superclasses

Abstract entities can be queried just like concrete queries. If an abstract entity is the target of a
query, the query operates on all the concrete subclasses of the abstract entity.
@Entity
public abstract class Employee {
@Id
protected Integer employeeId;
...
}
@Entity
public class FullTimeEmployee extends Employee {
protected Integer salary;
...
}
@Entity
public class PartTimeEmployee extends Employee {
protected Float hourlyWage;
}
Mapped Superclasses
Entities may inherit from superclasses that contain persistent state and mapping information,
but are not entities. That is, the superclass is not decorated with the @Entity annotation, and is
not mapped as an entity by the Java Persistence provider. These superclasses are most often
used when you have state and mapping information common to multiple entity classes.
Mapped superclasses are specified by decorating the class with the
javax.persistence.MappedSuperclass
annotation.
@MappedSuperclass
public class Employee {
@Id
protected Integer employeeId;
...
}
@Entity
public class FullTimeEmployee extends Employee {
protected Integer salary;
...
}
@Entity
public class PartTimeEmployee extends Employee {
protected Float hourlyWage;
...
}
Entities
The Java EE 5 Tutorial · September 2007
692