- Hibernate, as an ORM solution, effectively “sits between” the Java application data access layer and the Relational Database.
- As a JPA provider, Hibernate implements the Java Persistence API specifications.
JPA annotations
@Entity
The @Entity annotation is used to specify that the currently annotate class represents an entity type. Unlike basic and embeddable types, entity types have an identity and their state is managed by the underlying Persistence Context.
@Table
The @Table annotation is used to specify the primary table of the currently annotated entity.
@Column
The @Column annotation is used to specify the mapping between a basic entity attribute and the database table column.
@Id
The @Id annotation specifies the entity identifier. An entity must always have an identifier attribute which is used when loading the entity in a given Persistence Context.
@GeneratedValue
The @GeneratedValue annotation specifies that the entity identifier value is automatically generated using an identity column, a database sequence, or a table generator. Hibernate supports the @GeneratedValue mapping even for UUID identifiers.
@Temporal
The @Temporal annotation is used to specify the TemporalType of the currently annotated java.util.Date or java.util.Calendar entity attribute.
@Enumerated
The @Enumerated annotation is used to specify that an entity attribute represents an enumerated type.
@ManyToOne
The @ManyToOne annotation is used to specify a many-to-one database relationship.
@JoinColumn
The @JoinColumn annotation is used to specify the FOREIGN KEY column used when joining an entity association or an embeddable collection.
@OneToMany
If the @OneToMany doesn’t have a mirroring @ManyToOne association on the child side, the @OneToMany association is unidirectional. If there is a @ManyToOne association on the child side, the @OneToMany association is bidirectional and the application developer can navigate this relationship from both ends.
Every bidirectional association must have one owning side only (the child side), the other one being referred to as the inverse (or the mappedBy) side.
@OneToOne
The @OneToOne annotation is used to specify a one-to-one database relationship.
Hibernate annotations
@Where
The @Where annotation is used to specify a custom SQL WHERE clause used when fetching an entity or a collection.
ref
24. Mapping annotations
https://docs.jboss.org/hibernate/orm/5.3/userguide/html_single/Hibernate_User_Guide.html#annotations
All JPA Annotations: Mapping Annotations
Let’s take a look at ALL the JPA mapping annotations.
https://dzone.com/articles/all-jpa-annotations-mapping-annotations
javax.persistence
Annotation Type OneToMany
https://docs.oracle.com/javaee/7/api/javax/persistence/OneToMany.html
The best way to map a @OneToMany relationship with JPA and Hibernate
https://vladmihalcea.com/the-best-way-to-map-a-onetomany-association-with-jpa-and-hibernate/