25. Mapping annotations

25.1. JPA annotations

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

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

25.1.3. @AssociationOverrides

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

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

25.1.5. @AttributeOverrides

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

25.1.6. @Basic

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

See the Basic types chapter for more info.

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

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

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

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

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

See the Multiple scalar values NamedNativeQuery with ConstructorResult section for more info.

25.1.12. @Convert

The @Convert annotation is used to specify the AttributeConverter implementation used to convert the currently 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.

25.1.13. @Converter

The @Converter annotation is used to specify that the currently annotated 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.

25.1.14. @Converts

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

See the AttributeConverter section for more info.

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

25.1.16. @DiscriminatorValue

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

See the Discriminator section for more info.

25.1.17. @ElementCollection

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

See the Collections section for more info.

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

25.1.19. @Embedded

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

See the Embeddables section for more info.

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

25.1.21. @Entity

The @Entity annotation is used to specify that the currently annotated 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.

25.1.22. @EntityListeners

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

See the JPA callbacks section for more info.

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

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

25.1.25. @ExcludeDefaultListeners

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

See the Exclude default entity listeners section for more info.

25.1.26. @ExcludeSuperclassListeners

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

See the Exclude default entity listeners section for more info.

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

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

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

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

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

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

25.1.33. @Inheritance

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

See the Inheritance section for more info.

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

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

25.1.36. @JoinTable

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

See the @JoinTable mapping section for more info.

25.1.37. @Lob

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

See the BLOB mapping section for more info.

25.1.38. @ManyToMany

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

See the @ManyToMany mapping section for more info.

25.1.39. @ManyToOne

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

See the @ManyToOne mapping section for more info.

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

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

25.1.42. @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 for an example of @MapKeyColumn annotation usage.

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

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

25.1.45. @MapKeyJoinColumns

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

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

25.1.47. @MappedSuperclass

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

See the @MappedSuperclass section for more info.

25.1.48. @MapsId

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

See the @MapsId mapping section for more info.

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

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

25.1.51. @NamedEntityGraphs

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

25.1.52. @NamedNativeQueries

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

See the Custom CRUD mapping section for more info.

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

25.1.54. @NamedQueries

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

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

25.1.56. @NamedStoredProcedureQueries

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

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

25.1.58. @NamedSubgraph

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

See the Fetch subgraph section for more info.

25.1.59. @OneToMany

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

See the @OneToMany mapping section for more info.

25.1.60. @OneToOne

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

See the @OneToOne mapping section for more info.

25.1.61. @OrderBy

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

See the @OrderBy mapping section for more info.

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

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

25.1.64. @PersistenceContexts

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

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

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

25.1.67. @PersistenceUnits

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

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

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

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

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

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

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

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

25.1.75. @PrimaryKeyJoinColumn

The @PrimaryKeyJoinColumn annotation is used to specify that the primary key column of the currently 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.

25.1.76. @PrimaryKeyJoinColumns

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

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

25.1.78. @SecondaryTable

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

See the @SecondaryTable mapping section for more info.

25.1.79. @SecondaryTables

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

25.1.80. @SequenceGenerator

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

See the @SequenceGenerator mapping section for more info.

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

25.1.82. @SqlResultSetMappings

The @SqlResultSetMappings annotation is group multiple @SqlResultSetMapping annotations.

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

25.1.84. @Table

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

See the @Table mapping section for more info.

25.1.85. @TableGenerator

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

See the @TableGenerator mapping section for more info.

25.1.86. @Temporal

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

See the Basic temporal types chapter for more info.

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

25.1.88. @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 currently annotated entity.

See the Columns unique constraint chapter for more info.

25.1.89. @Version

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

See the Optimistic locking mapping section for more info.

25.2. Hibernate annotations

25.2.1. @AccessType

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

25.2.2. @Any

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

See the @Any mapping section for more info.

25.2.3. @AnyMetaDef

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

See the @Any mapping section for more info.

25.2.4. @AnyMetaDefs

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

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

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

25.2.7. @Cache

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

See the Caching chapter for more info.

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

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

25.2.10. @CollectionId

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

You might want to use the JPA @OrderColumn instead.

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

25.2.12. @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 a database column chapter for more info.

25.2.13. @Columns

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

See the @Columns mapping section for more info.

25.2.14. @ColumnTransformer

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

See the @ColumnTransformer mapping section for more info.

25.2.15. @ColumnTransformers

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

25.2.16. @CreationTimestamp

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

See the @CreationTimestamp mapping section for more info.

25.2.17. @DiscriminatorFormula

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

See the @DiscriminatorFormula section for more info.

25.2.18. @DiscriminatorOptions

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

See the Discriminator section for more info.

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

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

25.2.21. @Entity

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

25.2.22. @Fetch

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

See the @Fetch mapping section for more info.

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

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

25.2.25. @FetchProfiles

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

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

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

25.2.28. @FilterDefs

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

25.2.29. @FilterJoinTable

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

See the FilterJoinTable mapping section for more info.

25.2.30. @FilterJoinTables

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

25.2.31. @Filters

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

25.2.32. @ForeignKey

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

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

25.2.34. @Generated

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

See the @Generated mapping section for more info.

25.2.35. @GeneratorType

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

See the @GeneratorType mapping section for more info.

25.2.36. @GenericGenerator

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

See the @GenericGenerator mapping section for more info.

25.2.37. @GenericGenerators

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

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

25.2.39. @Index

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

25.2.40. @IndexColumn

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

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

25.2.42. @JoinColumnsOrFormulas

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

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

25.2.44. @LazyCollection

The @LazyCollection annotation is used to specify the lazy fetching behavior of a given collection. The possible values are given by the [LazyCollectionOption](https://docs.jboss.org/hibernate/orm/5.4/javadocs/org/hibernate/annotations/LazyCollectionOption.html) 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.

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

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

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

25.2.48. @Loader

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

See the Custom CRUD mapping section for more info.

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

25.2.50. @MapKeyType

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

See the @MapKeyType mapping section for more info.

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

25.2.52. @NamedNativeQueries

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

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

25.2.54. @NamedQueries

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

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

25.2.56. @Nationalized

The @Nationalized annotation is used to specify that the currently 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.

25.2.57. @NaturalId

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

See the Natural Ids section for more info.

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

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

25.2.60. @OnDelete

The @OnDelete annotation is used to specify the delete strategy employed by the currently 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.

25.2.61. @OptimisticLock

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

See the Excluding attributes section for more info.

25.2.62. @OptimisticLocking

The @OptimisticLocking annotation is used to specify the currently annotated entity’s 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.

25.2.63. @OrderBy

The @OrderBy annotation is used to specify a SQL ordering directive for sorting the currently 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.

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

25.2.65. @Parameter

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

25.2.66. @Parent

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

See the @Parent mapping section for more info.

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

25.2.68. @Polymorphism

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

There are two possible PolymorphismType options:

EXPLICIT

The currently annotated entity is retrieved only if explicitly asked.

IMPLICIT

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

See the @Polymorphism section for more info.

25.2.69. @Proxy

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

See the @Proxy mapping section for more info.

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

25.2.71. @SelectBeforeUpdate

The @SelectBeforeUpdate annotation is used to specify that the currently 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.

25.2.72. @Sort

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

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

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

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

25.2.76. @SQLDelete

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

See the Custom CRUD mapping section for more info.

25.2.77. @SQLDeleteAll

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

See the Custom CRUD mapping section for more info.

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

25.2.79. @SQLInsert

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

See the Custom CRUD mapping section for more info.

25.2.80. @SQLUpdate

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

See the Custom CRUD mapping section for more info.

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

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

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

25.2.84. @Tables

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

25.2.85. @Target

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

See the @Target mapping section for more info.

25.2.86. @Tuplizer

The @Tuplizer annotation is used to specify a custom tuplizer for the currently 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.

25.2.87. @Tuplizers

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

25.2.88. @Type

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

See the @Type mapping section for more info.

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

25.2.90. @TypeDefs

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

25.2.91. @UpdateTimestamp

The @UpdateTimestamp annotation is used to specify that the currently 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.

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

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

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