Mapping annotations

JPA annotations

@Access

The @Access annotation is used to specify the access type of the associated entity class, mapped superclass, or embeddable class, or entity attribute.

See the Access type section for more info.

@AssociationOverride

The @AssociationOverride annotation is used to override an association mapping (e.g. @ManyToOne, @OneToOne, @OneToMany, @ManyToMany) inherited from a mapped superclass or an embeddable.

See the Overriding Embeddable types section for more info.

@AssociationOverrides

The @AssociationOverrides is used to group several @AssociationOverride annotations.

@AttributeOverride

The @AttributeOverride annotation is used to override an attribute mapping inherited from a mapped superclass or an embeddable.

See the Overriding Embeddable types section for more info.

@AttributeOverrides

The @AttributeOverrides is used to group several @AttributeOverride annotations.

@Basic

The @Basic annotation is used to map a basic attribute type to a database column.

See the Basic types chapter for more info.

@Cacheable

The @Cacheable annotation is used to specify whether an entity should be stored in the second-level cache.

If the persistence.xml shared-cache-mode XML attribute is set to ENABLE_SELECTIVE, then only the entities annotated with the @Cacheable are going to be stored in the second-level cache.

If shared-cache-mode XML attribute value is DISABLE_SELECTIVE, then the entities marked with the @Cacheable annotation are not going to be stored in the second-level cache, while all the other entities are stored in the cache.

See the Caching chapter for more info.

@CollectionTable

The @CollectionTable annotation is used to specify the database table that stores the values of a basic or an embeddable type collection.

See the Collections of embeddable types section for more info.

@Column

The @Column annotation is used to specify the mapping between a basic entity attribute and the database table column.

See the @Column annotation section for more info.

@ColumnResult

The @ColumnResult annotation is used in conjunction with the @SqlResultSetMapping or @ConstructorResult annotations to map a SQL column for a given SELECT query.

See the Entity associations with named native queries section for more info.

@ConstructorResult

The @ConstructorResult annotation is used in conjunction with the @SqlResultSetMapping annotations to map columns of a given SELECT query to a certain object constructor.

@Convert

The @Convert annotation is used to specify the AttributeConverter implementation used to convert the current annotated basic attribute.

If the AttributeConverter uses autoApply, then all entity attributes with the same target type are going to be converted automatically.

See the AttributeConverter section for more info.

@Converter

The @Converter annotation is used to specify that the current annotate AttributeConverter implementation can be used as a JPA basic attribute converter.

If the autoApply attribute is set to true, then the JPA provider will automatically convert all basic attributes with the same Java type as defined by the current converter.

See the AttributeConverter section for more info.

@Converts

The @Converts annotation is used to group multiple @Convert annotations.

See the AttributeConverter section for more info.

@DiscriminatorColumn

The @DiscriminatorColumn annotation is used to specify the discriminator column name and the discriminator type for the SINGLE_TABLE and JOINED Inheritance strategies.

See the Discriminator section for more info.

@DiscriminatorValue

The @DiscriminatorValue annotation is used to specify what value of the discriminator column is used for mapping the current annotated entity.

See the Discriminator section for more info.

@ElementCollection

The @ElementCollection annotation is used to specify a collection of a basic or embeddable types.

See the Collections section for more info.

@Embeddable

The @Embeddable annotation is used to specify embeddable types. Like basic types, embeddable types do not have any identity, being managed by their owning entity.

See the Embeddables section for more info.

@Embedded

The @Embedded annotation is used to specify that a given entity attribute represents an embeddable type.

See the Embeddables section for more info.

@EmbeddedId

The @EmbeddedId annotation is used to specify the entity identifier is an embeddable type.

See the Composite identifiers with @EmbeddedId section for more info.

@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.

See the Entity section for more info.

@EntityListeners

The @EntityListeners annotation is used to specify an array of callback listener classes that are used by the current annotated entity.

See the JPA callbacks section for more info.

@EntityResult

The @EntityResult annotation is used with the @SqlResultSetMapping annotation to map the selected columns to an entity.

See the Entity associations with named native queries section for more info.

@Enumerated

The @Enumerated annotation is used to specify that an entity attribute represents an enumerated type.

See the @Enumerated basic type section for more info.

@ExcludeDefaultListeners

The @ExcludeDefaultListeners annotation is used to specify that the current annotated entity skips the invocation of any default listener.

See the Exclude default entity listeners section for more info.

@ExcludeSuperclassListeners

The @ExcludeSuperclassListeners annotation is used to specify that the current annotated entity skips the invocation of listeners declared by its superclass.

See the Exclude default entity listeners section for more info.

@FieldResult

The @FieldResult annotation is used with the @EntityResult annotation to map the selected columns to the fields of some specific entity.

See the Entity associations with named native queries section for more info.

@ForeignKey

The @ForeignKey annotation is used to specify the associated foreign key of a @JoinColumn mapping. The @ForeignKey annotation is only used if the automated schema generation tool is enabled, in which case, it allows you to customize the underlying foreign key definition.

See the @ManyToOne with @ForeignKey section for more info.

@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.

See the Automatically-generated identifiers section for more info.

@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.

See the Identifiers section for more info.

@IdClass

The @IdClass annotation is used if the current entity defined a composite identifier. A separate class encapsulates all the identifier attributes, which are mirrored by the current entity mapping.

See the Composite identifiers with @IdClass section for more info.

@Index

The @Index annotation is used by the automated schema generation tool to create a database index.

See the Columns index chapter for more info.

@Inheritance

The @Inheritance annotation is used to specify the inheritance strategy of a given entity class hierarchy.

See the Inheritance section for more info.

@JoinColumn

The @JoinColumn annotation is used to specify the FOREIGN KEY column used when joining an entity association or an embeddable collection.

See the @ManyToOne with @JoinColumn section for more info.

@JoinColumns

The @JoinColumns annotation is used to group multiple @JoinColumn annotations, which are used when mapping entity association or an embeddable collection using a composite identifier

@JoinTable

The @JoinTable annotation is used to specify the link table between two other database tables.

See the @JoinTable mapping section for more info.

@Lob

The @Lob annotation is used to specify that the current annotated entity attribute represents a large object type.

See the BLOB mapping section for more info.

@ManyToMany

The @ManyToMany annotation is used to specify a many-to-many database relationship.

See the @ManyToMany mapping section for more info.

@ManyToOne

The @ManyToOne annotation is used to specify a many-to-one database relationship.

See the @ManyToOne mapping section for more info.

@MapKey

The @MapKey annotation is used to specify the key of a java.util.Map association for which the key type is either the primary key or an attribute of the entity which represents the value of the map.

See the @MapKey mapping section for more info.

@MapKeyClass

The @MapKeyClass annotation is used to specify the type of the map key of a java.util.Map associations.

See the @MapKeyClass mapping section for more info.

@MapKeyColumn

The @MapKeyColumn annotation is used to specify the database column which stores the key of a java.util.Map association for which the map key is a basic type.

See the @MapKeyType mapping section section for an example of @MapKeyColumn annotation usage.

@MapKeyEnumerated

The @MapKeyEnumerated annotation is used to specify that the key of java.util.Map association is a Java Enum.

See the @MapKeyEnumerated mapping section for more info.

@MapKeyJoinColumn

The @MapKeyJoinColumn annotation is used to specify that the key of java.util.Map association is an entity association. The map key column is a FOREIGN KEY in a link table that also joins the Map owner’s table with the table where the Map value resides.

See the @MapKeyJoinColumn mapping section for more info.

@MapKeyJoinColumns

The @MapKeyJoinColumns annotation is used to group several @MapKeyJoinColumn mappings when the java.util.Map association key uses a composite identifier.

@MapKeyTemporal

The @MapKeyTemporal annotation is used to specify that the key of java.util.Map association is a @TemporalType (e.g. DATE, TIME, TIMESTAMP).

See the @MapKeyTemporal mapping section for more info.

@MappedSuperclass

The @MappedSuperclass annotation is used to specify that the current annotated type attributes are inherited by any subclass entity.

See the @MappedSuperclass section for more info.

@MapsId

The @MapsId annotation is used to specify that the entity identifier is mapped by the current annotated @ManyToOne or @OneToOne association.

See the @MapsId mapping section for more info.

@NamedAttributeNode

The @NamedAttributeNode annotation is used to specify each individual attribute node that needs to be fetched by an Entity Graph.

See the Fetch graph section for more info.

@NamedEntityGraph

The @NamedEntityGraph annotation is used to specify an Entity Graph that can be used by an entity query to override the default fetch plan.

See the Fetch graph section for more info.

@NamedEntityGraphs

The @NamedEntityGraphs annotation is used to group multiple @NamedEntityGraph annotations.

@NamedNativeQueries

The @NamedNativeQueries annotation is used to group multiple @NamedNativeQuery annotations.

See the Custom CRUD mapping section for more info.

@NamedNativeQuery

The @NamedNativeQuery annotation is used to specify a native SQL query that can be retrieved later by its name.

See the Custom CRUD mapping section for more info.

@NamedQueries

The @NamedQueries annotation is used to group multiple @NamedQuery annotations.

@NamedQuery

The @NamedQuery annotation is used to specify a JPQL query that can be retrieved later by its name.

See the @NamedQuery section for more info.

@NamedStoredProcedureQueries

The @NamedStoredProcedureQueries annotation is used to group multiple @NamedStoredProcedureQuery annotations.

@NamedStoredProcedureQuery

The @NamedStoredProcedureQuery annotation is used to specify a stored procedure query that can be retrieved later by its name.

See the Using named queries to call stored procedures section for more info.

@NamedSubgraph

The @NamedSubgraph annotation used to specify a subgraph in an Entity Graph.

See the Fetch subgraph section for more info.

@OneToMany

The @OneToMany annotation is used to specify a one-to-many database relationship.

See the @OneToMany mapping section for more info.

@OneToOne

The @OneToOne annotation is used to specify a one-to-one database relationship.

See the @OneToOne mapping section for more info.

@OrderBy

The @OrderBy annotation is used to specify the entity attributes used for sorting when fetching the current annotated collection.

See the @OrderBy mapping section for more info.

@OrderColumn

The @OrderColumn annotation is used to specify that the current annotation collection order should be materialized in the database.

See the @OrderColumn mapping section for more info.

@PersistenceContext

The @PersistenceContext annotation is used to specify the EntityManager that needs to be injected as a dependency.

See the @PersistenceContext mapping section for more info.

@PersistenceContexts

The @PersistenceContexts annotation is used to group multiple @PersistenceContext annotations.

@PersistenceProperty

The @PersistenceProperty annotation is used by the @PersistenceContext annotation to declare JPA provider properties that are passed to the underlying container when the EntityManager instance is created.

See the @PersistenceProperty mapping section for more info.

@PersistenceUnit

The @PersistenceUnit annotation is used to specify the EntityManagerFactory that needs to be injected as a dependency.

See the @PersistenceUnit mapping section for more info.

@PersistenceUnits

The @PersistenceUnits annotation is used to group multiple @PersistenceUnit annotations.

@PostLoad

The @PostLoad annotation is used to specify a callback method that fires after an entity is loaded.

See the JPA callbacks section for more info.

@PostPersist

The @PostPersist annotation is used to specify a callback method that fires after an entity is persisted.

See the JPA callbacks section for more info.

@PostRemove

The @PostRemove annotation is used to specify a callback method that fires after an entity is removed.

See the JPA callbacks section for more info.

@PostUpdate

The @PostUpdate annotation is used to specify a callback method that fires after an entity is updated.

See the JPA callbacks section for more info.

@PrePersist

The @PrePersist annotation is used to specify a callback method that fires before an entity is persisted.

See the JPA callbacks section for more info.

@PreRemove

The @PreRemove annotation is used to specify a callback method that fires before an entity is removed.

See the JPA callbacks section for more info.

@PreUpdate

The @PreUpdate annotation is used to specify a callback method that fires before an entity is updated.

See the JPA callbacks section for more info.

@PrimaryKeyJoinColumn

The @PrimaryKeyJoinColumn annotation is used to specify that the primary key column of the current annotated entity is also a foreign key to some other entity (e.g. a base class table in a JOINED inheritance strategy, the primary table in a secondary table mapping, or the parent table in a @OneToOne relationship).

See the @PrimaryKeyJoinColumn mapping section for more info.

@PrimaryKeyJoinColumns

The @PrimaryKeyJoinColumns annotation is used to group multiple @PrimaryKeyJoinColumn annotations.

@QueryHint

The @QueryHint annotation is used to specify a JPA provider hint used by a @NamedQuery or a @NamedNativeQuery annotation.

See the @QueryHint section for more info.

@SecondaryTable

The @SecondaryTable annotation is used to specify a secondary table for the current annotated entity.

See the @SecondaryTable mapping section for more info.

@SecondaryTables

The @SecondaryTables annotation is used to group multiple @SecondaryTable annotations.

@SequenceGenerator

The @SequenceGenerator annotation is used to specify the database sequence used by the identifier generator of the current annotated entity.

See the @SequenceGenerator mapping section for more info.

@SqlResultSetMapping

The @SqlResultSetMapping annotation is used to specify the ResultSet mapping of a native SQL query or stored procedure.

See the SqlResultSetMapping mapping section for more info.

@SqlResultSetMappings

The @SqlResultSetMappings annotation is group multiple @SqlResultSetMapping annotations.

@StoredProcedureParameter

The @StoredProcedureParameter annotation is used to specify a parameter of a @NamedStoredProcedureQuery.

See the Using named queries to call stored procedures section for more info.

@Table

The @Table annotation is used to specify the primary table of the current annotated entity.

See the @Table mapping section for more info.

@TableGenerator

The @TableGenerator annotation is used to specify the database table used by the identity generator of the current annotated entity.

See the @TableGenerator mapping section for more info.

@Temporal

The @Temporal annotation is used to specify the TemporalType of the current annotated java.util.Date or java.util.Calendar entity attribute.

See the Basic temporal types chapter for more info.

@Transient

The @Transient annotation is used to specify that a given entity attribute should not be persisted.

See the @Transient mapping section for more info.

@UniqueConstraint

The @UniqueConstraint annotation is used to specify a unique constraint to be included by the automated schema generator for the primary or secondary table associated with the current annotated entity.

See the Columns unique constraint chapter for more info.

@Version

The @Version annotation is used to specify the version attribute used for optimistic locking.

See the Optimistic locking mapping section for more info.

Hibernate annotations

@AccessType

The @AccessType annotation is deprecated. You should use either the JPA @Access or the Hibernate native @AttributeAccessor annotation.

@Any

The @Any annotation is used to define the any-to-one association which can point to one one of several entity types.

See the @Any mapping section for more info.

@AnyMetaDef

The @AnyMetaDef annotation is used to provide metadata about an @Any or @ManyToAny mapping.

See the @Any mapping section for more info.

@AnyMetaDefs

The @AnyMetaDefs annotation is used to group multiple @AnyMetaDef annotations.

@AttributeAccessor

The @AttributeAccessor annotation is used to specify a custom PropertyAccessStrategy.

Should only be used to name a custom PropertyAccessStrategy. For property/field access type, the JPA @Access annotation should be preferred.

However, if this annotation is used with either value="property" or value="field", it will act just as the corresponding usage of the JPA @Access annotation.

@BatchSize

The @BatchSize annotation is used to specify the size for batch loading the entries of a lazy collection.

See the Batch fetching section for more info.

@Cache

The @Cache annotation is used to specify the CacheConcurrencyStrategy of a root entity or a collection.

See the Caching chapter for more info.

@Cascade

The @Cascade annotation is used to apply the Hibernate specific CascadeType strategies (e.g. CascadeType.LOCK, CascadeType.SAVE_UPDATE, CascadeType.REPLICATE) on a given association.

For JPA cascading, prefer using the javax.persistence.CascadeType instead.

When combining both JPA and Hibernate CascadeType strategies, Hibernate will merge both sets of cascades.

See the Cascading chapter for more info.

@Check

The @Check annotation is used to specify an arbitrary SQL CHECK constraint which can be defined at the class level.

See the Database-level checks chapter for more info.

@CollectionId

The @CollectionId annotation is used to specify an identifier column for an idbag collection.

You might want to use the JPA @OrderColumn instead.

@CollectionType

The @CollectionType annotation is used to specify a custom collection type.

The collection can also name a @Type, which defines the Hibernate Type of the collection elements.

See the Custom collection types chapter for more info.

@ColumnDefault

The @ColumnDefault annotation is used to specify the DEFAULT DDL value to apply when using the automated schema generator.

The same behavior can be achieved using the definition attribute of the JPA @Column annotation.

See the Default value for database column chapter for more info.

@Columns

The @Columns annotation is used to group multiple JPA @Column annotations.

See the @Columns mapping section for more info.

@ColumnTransformer

The @ColumnTransformer annotation is used to customize how a given column value is read from or write into the database.

See the @ColumnTransformer mapping section for more info.

@ColumnTransformers

The @ColumnTransformers annotation iis used to group multiple @ColumnTransformer annotations.

@CreationTimestamp

The @CreationTimestamp annotation is used to specify that the current annotated temporal type must be initialized with the current JVM timestamp value.

See the @CreationTimestamp mapping section for more info.

@DiscriminatorFormula

The @DiscriminatorFormula annotation is used to specify a Hibernate @Formula to resolve the inheritance discriminator value.

See the @DiscriminatorFormula section for more info.

@DiscriminatorOptions

The @DiscriminatorOptions annotation is used to provide the force and insert Discriminator properties.

See the Discriminator section for more info.

@DynamicInsert

The @DynamicInsert annotation is used to specify that the INSERT SQL statement should be generated whenever an entity is to be persisted.

By default, Hibernate uses a cached INSERT statement that sets all table columns. When the entity is annotated with the @DynamicInsert annotation, the PreparedStatement is going to include only the non-null columns.

See the @CreationTimestamp mapping section for more info on how @DynamicInsert works.

@DynamicUpdate

The @DynamicUpdate annotation is used to specify that the UPDATE SQL statement should be generated whenever an entity is modified.

By default, Hibernate uses a cached UPDATE statement that sets all table columns. When the entity is annotated with the @DynamicUpdate annotation, the PreparedStatement is going to include only the columns whose values have been changed.

See the @DynamicUpdate section for more info.

For reattachment of detached entities, the dynamic update is not possible without having the @SelectBeforeUpdate annotation as well.

@Entity

The @Entity annotation is deprecated. Use the JPA @Entity annotation instead.

@Fetch

The @Fetch annotation is used to specify the Hibernate specific FetchMode (e.g. JOIN, SELECT, SUBSELECT) used for the current annotated association:

See the @Fetch mapping section for more info.

@FetchProfile

The @FetchProfile annotation is used to specify a custom fetching profile, similar to a JPA Entity Graph.

See the Fetch mapping section for more info.

@FetchProfile.FetchOverride

The @FetchProfile.FetchOverride annotation is used in conjunction with the @FetchProfile annotation, and it’s used for overriding the fetching strategy of a particular entity association.

See the Fetch profile section for more info.

@FetchProfiles

The @FetchProfiles annotation is used to group multiple @FetchProfile annotations.

@Filter

The @Filter annotation is used to add filters to an entity or the target entity of a collection.

See the Filter mapping section for more info.

@FilterDef

The @FilterDef annotation is used to specify a @Filter definition (name, default condition and parameter types, if any).

See the Filter mapping section for more info.

@FilterDefs

The @FilterDefs annotation is used to group multiple @FilterDef annotations.

@FilterJoinTable

The @FilterJoinTable annotation is used to add @Filter capabilities to a join table collection.

See the FilterJoinTable mapping section for more info.

@FilterJoinTables

The @FilterJoinTables annotation is used to group multiple @FilterJoinTable annotations.

@Filters

The @Filters annotation is used to group multiple @Filter annotations.

@ForeignKey

The @ForeignKey annotation is deprecated. Use the JPA 2.1 @ForeignKey annotation instead.

@Formula

The @Formula annotation is used to specify an SQL fragment that is executed in order to populate a given entity attribute.

See the @Formula mapping section for more info.

@Generated

The @Generated annotation is used to specify that the current annotated entity attribute is generated by the database.

See the @Generated mapping section for more info.

@GeneratorType

The @GeneratorType annotation is used to provide a ValueGenerator and a GenerationTime for the current annotated generated attribute.

See the @GeneratorType mapping section for more info.

@GenericGenerator

The @GenericGenerator annotation can be used to configure any Hibernate identifier generator.

See the @GenericGenerator mapping section for more info.

@GenericGenerators

The @GenericGenerators annotation is used to group multiple @GenericGenerator annotations.

@Immutable

The @Immutable annotation is used to specify that the annotated entity, attribute, or collection is immutable.

See the @Immutable mapping section for more info.

@Index

The @Index annotation is deprecated. Use the JPA @Index annotation instead.

@IndexColumn

The @IndexColumn annotation is deprecated. Use the JPA @OrderColumn annotation instead.

@JoinColumnOrFormula

The @JoinColumnOrFormula annotation is used to specify that the entity association is resolved either through a FOREIGN KEY join (e.g. @JoinColumn) or using the result of a given SQL formula (e.g. @JoinFormula).

See the @JoinColumnOrFormula mapping section for more info.

@JoinColumnsOrFormulas

The @JoinColumnsOrFormulas annotation is used to group multiple @JoinColumnOrFormula annotations.

@JoinFormula

The @JoinFormula annotation is used as a replacement for @JoinColumn when the association does not have a dedicated FOREIGN KEY column.

See the @JoinFormula mapping section for more info.

@LazyCollection

The @LazyCollection annotation is used to specify the lazy fetching behavior of a given collection. The possible values are given by the LazyCollectionOption enumeration:

TRUE

Load it when the state is requested.

FALSE

Eagerly load it.

EXTRA

Prefer extra queries over full collection loading.

The TRUE and FALSE values are deprecated since you should be using the JPA FetchType attribute of the @ElementCollection, @OneToMany, or @ManyToMany collection.

The EXTRA value has no equivalent in the JPA specification, and it’s used to avoid loading the entire collection even when the collection is accessed for the first time. Each element is fetched individually using a secondary query.

See the @LazyCollection mapping section for more info.

@LazyGroup

The @LazyGroup annotation is used to specify that an entity attribute should be fetched along with all the other attributes belonging to the same group.

To load entity attributes lazily, bytecode enhancement is needed. By default, all non-collection attributes are loaded in one group named "DEFAULT".

This annotation allows defining different groups of attributes to be initialized together when access one attribute in the group.

See the @LazyGroup mapping section for more info.

@LazyToOne

The @LazyToOne annotation is used to specify the laziness options, represented by LazyToOneOption, available for a @OneToOne or @ManyToOne association.

LazyToOneOption defines the following alternatives:

FALSE

Eagerly load the association. This one is not needed since the JPA FetchType.EAGER offers the same behavior.

NO_PROXY

This option will fetch the association lazily while returning real entity object.

PROXY

This option will fetch the association lazily while returning a proxy instead.

See the @LazyToOne mapping example section for more info.

@ListIndexBase

The @ListIndexBase annotation is used to specify the start value for a list index, as stored in the database.

By default, List indexes are stored starting at zero. Generally used in conjunction with @OrderColumn.

See the @ListIndexBase mapping section for more info.

@Loader

The @Loader annotation is used to override the default SELECT query used for loading an entity loading.

See the Custom CRUD mapping section for more info.

@ManyToAny

The @ManyToAny annotation is used to specify a many-to-one association when the target type is dynamically resolved.

See the @ManyToAny mapping section for more info.

@MapKeyType

The @MapKeyType annotation is used to specify the map key type.

See the @MapKeyType mapping section for more info.

@MetaValue

The @MetaValue annotation is used by the @AnyMetaDef annotation to specify the association between a given discriminator value and an entity type.

See the @Any mapping section for more info.

@NamedNativeQueries

The @NamedNativeQueries annotation is used to group multiple @NamedNativeQuery annotations.

@NamedNativeQuery

The @NamedNativeQuery annotation extends the JPA @NamedNativeQuery with Hibernate specific features, like:

  • flush mode for this particular query

  • if the query should be cached, and which cache region should be used

  • the selected entity CacheModeType strategy

  • the JDBC Statement fetch size

  • the JDBC Statement execution timeout

  • if the query is a CallableStatement, targeting a stored procedure or a database function

  • what SQL-level comment should be sent to the database

  • if the query is read-only, hence it does not store the resulted entities into the currently running Persistence Context

See the Hibernate @NamedNativeQuery section for more info.

@NamedQueries

The @NamedQueries annotation is used to group multiple @NamedQuery annotations.

@NamedQuery

The @NamedQuery annotation extends the JPA @NamedQuery with Hibernate specific features, like:

  • flush mode for this particular query

  • if the query should be cached, and which cache region should be used

  • the selected entity CacheModeType strategy

  • the JDBC Statement fetch size

  • the JDBC Statement execution timeout

  • if the query is a CallableStatement, targeting a stored procedure or a database function

  • what SQL-level comment should be sent to the database

  • if the query is read-only, hence it does not store the resulted entities into the currently running Persistence Context

See the @NamedQuery section for more info.

@Nationalized

The @Nationalized annotation is used to specify that the current annotated attribute is a character type (e.g. String, Character, Clob) that is stored in a nationalized column type (NVARCHAR, NCHAR, NCLOB).

See the @Nationalized mapping section for more info.

@NaturalId

The @NaturalId annotation is used to specify that the current annotated attribute is part of the natural id of the entity.

See the Natural Ids section for more info.

@NaturalIdCache

The @NaturalIdCache annotation is used to specify that the natural id values associated with the annotated entity should be stored in the second-level cache.

See the @NaturalIdCache mapping section for more info.

@NotFound

The @NotFound annotation is used to specify the NotFoundAction strategy for when an element is not found in a given association.

The NotFoundAction defines with two possibilities:

EXCEPTION

An exception is thrown when an element is not found (default and recommended).

IGNORE

Ignore the element when not found in the database.

See the @NotFound mapping section for more info.

@OnDelete

The @OnDelete annotation is used to specify the delete strategy employed by the current annotated collection, array or joined subclasses. This annotation is used by the automated schema generation tool to generated the appropriate FOREIGN KEY DDL cascade directive.

The two possible strategies are defined by the OnDeleteAction enumeration:

CASCADE

Use the database FOREIGN KEY cascade capabilities.

NO_ACTION

Take no action.

See the @OnDelete cascade chapter for more info.

@OptimisticLock

The @OptimisticLock annotation is used to specify if the current annotated attribute will trigger an entity version increment upon being modified.

See the Excluding attributes section for more info.

@OptimisticLocking

The @OptimisticLocking annotation is used to specify the current annotated an entity optimistic locking strategy.

The four possible strategies are defined by the OptimisticLockType enumeration:

NONE

The implicit optimistic locking mechanism is disabled.

VERSION

The implicit optimistic locking mechanism is using a dedicated version column.

ALL

The implicit optimistic locking mechanism is using all attributes as part of an expanded WHERE clause restriction for the UPDATE and DELETE SQL statements.

DIRTY

The implicit optimistic locking mechanism is using the dirty attributes (the attributes that were modified) as part of an expanded WHERE clause restriction for the UPDATE and DELETE SQL statements.

See the Versionless optimistic locking section for more info.

@OrderBy

The @OrderBy annotation is used to specify a SQL ordering directive for sorting the current annotated collection.

It differs from the JPA @OrderBy annotation because the JPA annotation expects a JPQL order-by fragment, not an SQL directive.

See the @OrderBy mapping section for more info.

@ParamDef

The @ParamDef annotation is used in conjunction with @FilterDef so that the Hibernate Filter can be customized with runtime-provided parameter values.

See the Filter mapping section for more info.

@Parameter

The @Parameter annotation is generic parameter (basically a key/value combination) tused to parametrize other annotations, like @CollectionType, @GenericGenerator, and @Type, @TypeDef.

@Parent

The @Parent annotation is used to specify that the current annotated embeddable attribute references back the owning entity.

See the @Parent mapping section for more info.

@Persister

The @Persister annotation is used to specify a custom entity or collection persister.

For entities, the custom persister must implement the EntityPersister interface.

For collections, the custom persister must implement the CollectionPersister interface.

See the @Persister mapping section for more info.

@Polymorphism

The @Polymorphism annotation is used to define the PolymorphismType Hibernate will apply to entity hierarchies.

There are two possible PolymorphismType options:

EXPLICIT

The current annotated entity is retrieved only if explicitly asked.

IMPLICIT

The current annotated entity is retrieved if any of its super entity are retrieved. This is the default option.

See the @Polymorphism section for more info.

@Proxy

The @Proxy annotation is used to specify a custom proxy implementation for the current annotated entity.

See the @Proxy mapping section for more info.

@RowId

The @RowId annotation is used to specify the database column used as a ROWID pseudocolumn. For instance, Oracle defines the ROWID pseudocolumn which provides the address of every table row.

According to Oracle documentation, ROWID is the fastest way to access a single row from a table.

See the @RowId mapping section for more info.

@SelectBeforeUpdate

The @SelectBeforeUpdate annotation is used to specify that the current annotated entity state be selected from the database when determining whether to perform an update when the detached entity is reattached.

See the OptimisticLockType.DIRTY mapping section for more info on how @SelectBeforeUpdate works.

@Sort

The @Sort annotation is deprecated. Use the Hibernate specific @SortComparator or @SortNatural annotations instead.

@SortComparator

The @SortComparator annotation is used to specify a Comparator for sorting the Set/Map in-memory.

See the @SortComparator mapping section for more info.

@SortNatural

The @SortNatural annotation is used to specify that the Set/Map should be sorted using natural sorting.

See the @SortNatural mapping section for more info.

@Source

The @Source annotation is used in conjunction with a @Version timestamp entity attribute indicating the SourceType of the timestamp value.

The SourceType offers two options:

DB

Get the timestamp from the database.

VM

Get the timestamp from the current JVM.

See the Database-generated version timestamp mapping section for more info.

@SQLDelete

The @SQLDelete annotation is used to specify a custom SQL DELETE statement for the current annotated entity or collection.

See the Custom CRUD mapping section for more info.

@SQLDeleteAll

The @SQLDeleteAll annotation is used to specify a custom SQL DELETE statement when removing all elements of the current annotated collection.

See the Custom CRUD mapping section for more info.

@SqlFragmentAlias

The @SqlFragmentAlias annotation is used to specify an alias for a Hibernate @Filter.

The alias (e.g. myAlias) can then be used in the @Filter condition clause using the {alias} (e.g. {myAlias}) placeholder.

See the @SqlFragmentAlias mapping section for more info.

@SQLInsert

The @SQLInsert annotation is used to specify a custom SQL INSERT statement for the current annotated entity or collection.

See the Custom CRUD mapping section for more info.

@SQLUpdate

The @SQLUpdate annotation is used to specify a custom SQL UPDATE statement for the current annotated entity or collection.

See the Custom CRUD mapping section for more info.

@Subselect

The @Subselect annotation is used to specify an immutable and read-only entity using a custom SQL SELECT statement.

See the Mapping the entity to a SQL query section for more info.

@Synchronize

The @Synchronize annotation is usually used in conjunction with the @Subselect annotation to specify the list of database tables used by the @Subselect SQL query.

With this information in place, Hibernate will properly trigger an entity flush whenever a query targeting the @Subselect entity is to be executed while the Persistence Context has scheduled some insert/update/delete actions against the database tables used by the @Subselect SQL query.

Therefore, the @Synchronize annotation prevents the derived entity from returning stale data when executing entity queries against the @Subselect entity.

See the Mapping the entity to a SQL query section for more info.

@Table

The @Table annotation is used to specify additional information to a JPA @Table annotation, like custom INSERT, UPDATE or DELETE statements or a specific FetchMode.

See the @SecondaryTable mapping section for more info about Hibernate-specific @Table mapping.

@Tables

The @Tables annotation is used to group multiple @Table annotations.

@Target

The @Target annotation is used to specify an explicit target implementation when the current annotated association is using an interface type.

See the @Target mapping section for more info.

@Tuplizer

The @Tuplizer annotation is used to specify a custom tuplizer for the current annotated entity or embeddable.

For entities, the tupelizer must implement the EntityTuplizer interface.

For embeddables, the tupelizer must implement the ComponentTuplizer interface.

See the @Tuplizer mapping section for more info.

@Tuplizers

The @Tuplizers annotation is used to group multiple @Tuplizer annotations.

@Type

The @Type annotation is used to specify the Hibernate @Type used by the current annotated basic attribute.

See the @Type mapping section for more info.

@TypeDef

The @TypeDef annotation is used to specify a @Type definition which can later be reused for multiple basic attribute mappings.

See the @TypeDef mapping section for more info.

@TypeDefs

The @TypeDefs annotation is used to group multiple @TypeDef annotations.

@UpdateTimestamp

The @UpdateTimestamp annotation is used to specify that the current annotated timestamp attribute should be updated with the current JVM timestamp whenever the owning entity gets modified.

  • java.util.Date

  • java.util.Calendar

  • java.sql.Date

  • java.sql.Time

  • java.sql.Timestamp

See the @UpdateTimestamp mapping section for more info.

@ValueGenerationType

The @ValueGenerationType annotation is used to specify that the current annotation type should be used as a generator annotation type.

See the @ValueGenerationType mapping section for more info.

@Where

The @Where annotation is used to specify a custom SQL WHERE clause used when fetching an entity or a collection.

See the @Where mapping section for more info.

@WhereJoinTable

The @WhereJoinTable annotation is used to specify a custom SQL WHERE clause used when fetching a join collection table.

See the @WhereJoinTable mapping section for more info.