JPA : Class Mapping

The first thing to decide when implementing your persistence layer is which classes are to be
persisted. If you need to persist a field/property then you must mark that class as persistable.
In JPA there are three types of persistable classes.

Entity - persistable class with full control over its persistence.

MappedSuperclass - persistable class that will not be persisted into its own table
simply providing some fields to be persisted. Consequently an inheritance tree cannot just
have a mapped superclass on its own.
Read more

Embeddable - persistable class that is only persistable embedded into
an entity class.
Read more

Let's take a sample class (Hotel) as an example
We can define a class as persistable using either annotations in the class, or XML metadata.

In the above example we have marked the class as an entity. We could equally have
marked it as mapped-superclass
(using annotation @MappedSuperclass, or XML element <mapped-superclass>) or
as embeddable
(using annotation @Embeddable, or XML element <embeddable>).