liveBook · Manning

Mapping metadata

As explained in Java Persistence with Spring Data and Hibernate epub

Mapping metadata is configuration that describes how application classes and properties correspond to a relational database schema.

Mapping metadata tells an ORM tool how to persist a Java domain model in a relational database. It links classes to tables, properties to columns, associations to foreign keys, and Java types to SQL types. The tool uses those descriptions to transform data between objects and database rows; the mappings must be created and maintained as the model changes. section 1.3 section 3.3

JPA offers two standard ways to supply mappings:

  • Put annotations beside the Java declarations they describe. Annotations are type-safe, and Java development tools can validate them and include them in refactoring operations. section 3.3 section 3.3.1
  • Keep mappings in external XML descriptor files deployed with the compiled classes. This separates mapping declarations from Java source, but typical Java refactoring tools cannot update XML names as reliably as annotations. section 3.0 section 3.3.1
import javax.persistence.Entity;
@Entity
public class Item {
}

A minimal mapping: @Entity marks Item as persistent. With the default strategy, its attributes become persistent managed state, so instances can be loaded and stored. section 3.3.1

For annotation-based mappings, JPA metadata is compiled into class files. Hibernate reads it through reflection when the application starts. Compiling an annotated class requires JPA libraries; merely creating an instance without accessing the annotations does not. Hibernate-specific annotations can supplement standard JPA mappings when a needed option is not standardized. section 3.3.1 section 3.3.1

Mapping metadata does not remove the need to understand the relational schema or inspect generated SQL. The JPA Metamodel API can expose the persistent entities, attributes, and mapping metadata of a persistence unit when code needs to examine them. section 1.3 section 3.0

How Java Persistence with Spring Data and Hibernate epub covers it

How deep it goes
Explains mapping categories, annotation and XML options, and annotation-loading behavior; stops short of a worked XML mapping.
Examples
Uses an @Entity-annotated Item class to show default persistence of an entity’s attributes.
What it assumes
Assumes familiarity with Java classes and relational tables while defining metadata’s role in object/relational mapping.
What you can do after
Apply it via JPA annotations or XML descriptors to specify persistent classes and properties, choosing annotations when Java tooling benefits matter.
How it connects
Connects object/relational mapping, JPA, Hibernate, Java reflection, relational schemas, and the JPA Metamodel API.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Java Persistence with Spring Data and Hibernate epub. The section links point to the parts of the book it draws on.