liveBook · Manning

Attribute

As explained in Java Persistence with Spring Data and Hibernate epub

An annotation is declarative metadata attached to a program element to provide configuration or other information to tools and frameworks.

An annotation is declarative metadata attached to a program element. Persistence frameworks use annotations to describe mappings, validation, identifiers, indexes, constructors, and fields that should not be stored. section 3.3 section 17.2

Mapping a Java class

A JPA entity can be declared directly beside the class it describes: import javax.persistence.Entity; @Entity public class Item { } The annotation is compiled into the class file, remains available through reflection, and can be validated and refactored by Java-aware tools. A provider can also add vendor-specific annotations for features such as caching. section 3.3.1

Common annotation roles include:

  • Declare persistence: @Entity identifies a JPA entity, while @Document identifies a MongoDB document. section 3.3.1 section 17.2
  • Control stored state: @Id marks an identifier, and @Transient excludes a field from persistence. section 17.2
  • Configure database structures: @Indexed and @CompoundIndex define MongoDB indexes. section 17.2
  • Select construction and generated code: @PersistenceConstructor chooses a retrieval constructor, while Lombok annotations generate constructors, getters, and setters. section 17.2
import javax.persistence.Entity;
@Entity
public class Item {
}

Use the minimal @Entity listing to inspect how persistence metadata sits directly beside the Java class declaration. section 3.3.1

How Java Persistence with Spring Data and Hibernate epub covers it

How deep it goes
Explains placement, compilation, reflection, refactoring, vendor extensions, and concrete persistence roles, while deferring complete mapping configuration.
Examples
Uses @Entity on Item and combines @Document, @Id, @Indexed, @Transient, @PersistenceConstructor, and Lombok annotations on User.
What it assumes
Assumes core Java classes and compilation, while teaching annotation-based metadata and its runtime access through reflection.
What you can do after
Apply annotations to declare Java persistence metadata and configure MongoDB mapping, indexes, identifiers, fields, constructors, and generated accessors.
How it connects
Connects annotations with metadata, ORM, JPA, XML descriptors, reflection, Bean Validation, Spring Data MongoDB, and Lombok.

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.