Chapter 3. Hibernate Annotations
3.1. Hibernate Annotations
The org.hibernate.annotations
package contains some annotations which are offered by Hibernate, on top of the standard JPA annotations.
Annotation | Description |
---|---|
| Arbitrary SQL check constraints which can be defined at the class, property or collection level. |
| Mark an Entity or a Collection as immutable. No annotation means the element is mutable. An immutable entity may not be updated by the application. Updates to an immutable entity will be ignored, but no exception is thrown.
|
Annotation | Description |
---|---|
| Add caching strategy to a root entity or a collection. |
Annotation | Description |
---|---|
| Defines the type of key of a persistent map. |
|
Defines a |
| Order a collection using SQL ordering (not HQL ordering). |
|
Strategy to use on collections, arrays and on joined subclasses delete. |
| Specify a custom persister. |
| Collection sort (Java level sorting). |
| Where clause to add to the element Entity or target entity of a collection. The clause is written in SQL. |
| Where clause to add to the collection join table. The clause is written in SQL. |
Annotation | Description |
---|---|
|
Overwrites Hibernate default |
|
Overwrites the Hibernate default |
|
Overwrites the Hibernate default |
|
Overwrites the Hibernate default |
|
Overwrites the Hibernate default |
| Maps an immutable and read-only entity to a given SQL subselect expression. |
|
Ensures that auto-flush happens correctly and that queries against the derived entity do not return stale data. Mostly used with |
Annotation | Description |
---|---|
| Apply a cascade strategy on an association. |
|
Adds additional metadata that may be needed beyond what is defined in the standard
|
| Used to define the type of polymorphism Hibernate will apply to entity hierarchies. |
| Lazy and proxy configuration of a particular class. |
| Complementary information to a table either primary or secondary. |
| Plural annotation of Table. |
| Defines an explicit target, avoiding reflection and generics resolving. |
| Defines a tuplizer for an entity or a component. |
| Defines a set of tuplizers for an entity or a component. |
Annotation | Description |
---|---|
| Batch size for SQL loading. |
| Defines the fetching strategy profile. |
|
Plural annotation for |
|
Specifies that an entity attribute should be fetched along with all the other attributes belonging to the same group. In order to load entity attributes lazily, bytecode enhancement is needed. By default, all non-collection attributes are loaded in one group named |
Annotation | Description |
---|---|
| Adds filters to an entity or a target entity of a collection. |
| Filter definition. |
| Array of filter definitions. |
| Adds filters to a join table collection. |
|
Adds multiple |
|
Adds multiple |
| A parameter definition. |
Annotation | Description |
---|---|
| This annotated property is generated by the database. |
| Generator annotation describing any kind of Hibernate generator in a detyped manner. |
| Array of generic generator definitions. |
| Specifies that a property is part of the natural id of the entity. |
| Key/value pattern. |
|
Support for |
Annotation | Description |
---|---|
| Discriminator formula to be placed at the root entity. |
| Optional annotation to express Hibernate specific discriminator properties. |
| Maps a given discriminator value to the corresponding entity type. |
Annotation | Description |
---|---|
|
Extends |
|
Extends |
|
Extends |
|
Extends |
Annotation | Description |
---|---|
| Property access type. |
| Support an array of columns. Useful for component user type mappings. |
| Custom SQL expression used to read the value from and write a value to a column. Use for direct object loading/saving as well as queries. The write expression must contain exactly one '?' placeholder for the value. |
|
Plural annotation for |
Annotation | Description |
---|---|
|
To be used as a replacement for |
| Defines a database index. |
|
To be used as a replacement for |
| Reference the property as a pointer back to the owner (generally the owning entity). |
| Hibernate type. |
| Hibernate type definition. |
| Hibernate type definition array. |
Annotation | Description |
---|---|
| Defines a ToOne association pointing to several entity types. Matching the according entity type is done through a metadata discriminator column. This kind of mapping should be only marginal. |
|
Defines |
|
Defines |
| Defines the fetching strategy used for the given association. |
| Defines the lazy status of a collection. |
|
Defines the lazy status of a ToOne association (i.e. |
| Action to do when an element is not found on an association. |
Annotation | Description |
---|---|
| Whether or not a change of the annotated property will trigger an entity version increment. If the annotation is not present, the property is involved in the optimistic lock strategy (default). |
| Used to define the style of optimistic locking to be applied to an entity. In a hierarchy, only valid on the root entity. |
| Optional annotation in conjunction with Version and timestamp version properties. The annotation value decides where the timestamp is generated. |