This section describes the list of annotations included in the javax.persistence package and the precautions to be taken when specifying annotations.
You can also specify the mapping information in an O/R mapping file instead of the annotations. For details on the correspondence between the annotations and the O/R mapping files, see 2.7.64 Correspondence between the annotations and O/R mapping.
Annotation classification | Annotation name | Overview |
---|---|---|
Entity annotation | @Entity | Indicates that the class is an entity. |
Annotations related to the tables or columns | @Column | Specifies the mapping between the persistence field or the persistence property, and the columns of the database. |
@JoinColumn | Specifies the external key column for the binding table or a column of the binding--destination table that is referenced from the external key column by correlating the entity classes. | |
@JoinColumns | Used when multiple @JoinColumns are coded concurrently. | |
@JoinTable | This annotation specifies the binding table set up in the following classes:
| |
@PrimaryKeyJoinColumn | Specifies the column used as the external key, when binding with other tables. | |
@PrimaryKeyJoinColumns | Used when multiple @PrimaryKeyJoinColumns are coded concurrently. | |
@SecondaryTable | Specifies a secondary table in the entity class. | |
@SecondaryTables | Used when multiple @SecondaryTables are coded concurrently. | |
@Table | Specifies a primary table in the entity class. | |
@UniqueConstraint | If you want to generate CREATE sentences for the primary table or secondary table, include the unique constraints, and then specify. Note that this annotation is not supported with Cosminexus JPA provider CJPA provider. | |
Annotations related to the ID | @EmbeddedId | Specifies the compound primary key of a class that can be embedded. |
@GeneratedValue | Specifies the method for automatically generating and allotting a unique value to the primary key column. | |
@Id | Specifies the properties or fields of the primary key of the entity class. | |
@IdClass | Specifies the compound primary key class mapped to multiple fields or properties of the entity class. | |
@SequenceGenerator | Specifies the settings of the sequence generator that creates the primary key. | |
@TableGenerator | Specifies the settings of the generator that creates the primary key. | |
Lock annotation | @Version | Specifies the version field or the version property for using the optimistic lock functionality. |
Annotations related to mapping | @Basic | Indicates the type of mapping to the simplest database column. |
@Embeddable | Specifies an embedded class. | |
@Embedded | Specifies the persistence property or the persistence field indicating the instance value of the embedded class within the entity class at the embedding destination. | |
@Enumerated | Specifies the persistence field or the persistence property as the enumeration type. | |
@Lob | Specifies the persistence field or the persistence property of the large object type supported by the database. | |
@MapKey | Specifies the map key used for object identification within the map, when a non--owner entity class is indicated by the java.util.Map type in the OneToMany relationship or the ManyToMany relationship. | |
@OrderBy | Specifies the order in which the collection is evaluated when the entity information is acquired. | |
@Temporal | Specifies in the persistence property or persistence field having the type that expresses the time (java.util.Date and java.util.Calendar). | |
@Transient | Specifies the field or property of a non--persisting entity class, mapped superclass, or embedded class. | |
Annotations related to the relationship | @ManyToMany | Indicates that the specified class has a ManyToMany relationship, and also specifies the multiple relationships from the owner entity class to the non--owner entity class. |
@ManyToOne | Indicates that the specified class has the ManyToOne relationship, and also specifies the relationship to the non--owner entity class. | |
@OneToMany | Indicates that the specified class has the OneToMany relationship, and also specifies the multiple relationships from the owner entity class to the non--owner entity class. | |
@OneToOne | Indicates that the specified class has the OneToOne relationship, and also specifies the single relationship between entity classes. | |
Annotations related to inheritance and overriding | @AssociationOverride | Overrides the settings used in the ManyToOne relationship or the OneToOne relationship specified in a mapped superclass and embedded class. |
@AssociationOverrides | Used when multiple @AssociationOverrides are coded concurrently. | |
@AttributeOverride | Overrides the following mapping information:
| |
@AttributeOverrides | Used when multiple @ElementOverrides are coded concurrently. | |
@DiscriminatorColumn | Specifies the column used for identification in the SINGLE_TABLE strategy or JOINED strategy. This annotation is added to an entity class that becomes a superclass by inheriting an entity class. | |
@DiscriminatorValue | Specifies the value of the column used for identification in the SINGLE_TABLE strategy or JOINED strategy. | |
@Inheritance | Specifies the inheritance mapping strategy used in the entity class hierarchy. | |
@MappedSuperclass | Specifies a mapped superclass. | |
Annotations related to queries | @ColumnResult | Specifies the column for mapping the query results of an SQL to the entity class. |
@EntityResult | Specifies the entity class in which the query results of the SQL are to be mapped. | |
@FieldResult | Specifies the field in which the query results of the SQL are to be mapped. | |
@NamedNativeQueries | Used when multiple @NamedNativeQueries are coded concurrently. | |
@NamedNativeQuery | Specifies a named query in the SQL. | |
@NamedQueries | Used when multiple @NamedQueries are coded concurrently. | |
@NamedQuery | Specifies a named query of JPQL. | |
@QueryHint | Specifies a database--specific query hint. | |
@SqlResultSetMapping | Specifies the result set mapping of an SQL query. | |
@SqlResultSetMappings | Used when multiple @SqlResultSetMappings are coded concurrently. | |
Annotations related to event callback# | @EntityListeners | Specifies the callback listener class used in the entity class or mapped superclass. |
@ExcludeDefaultListeners | This annotation excludes the default listener for the following classes:
| |
@ExcludeSuperclassListeners | This annotation excludes the superclass listener for the following classes:
| |
@PostLoad | This annotation indicates the callback method invoked after the SELECT statement is issued in the database. | |
@PostPersist | This annotation indicates the callback method invoked after the INSERT statement is issued in the database. | |
@PostRemove | This annotation indicates the callback method invoked after the DELETE statement is issued in the database. | |
@PostUpdate | This annotation indicates the callback method invoked after the UPDATE statement is issued in the database. | |
@PrePersist | This annotation indicates the callback method invoked before the INSERT statement is issued in the database. | |
@PreRemove | This annotation indicates the callback method invoked before the DELETE statement is issued in the database. | |
@PreUpdate | This annotation indicates the callback method invoked before the UPDATE statement is issued in the database. | |
Annotations related to the reference of EntityManager and EntityManagerFactory | @PersistenceContext | Defines the container--managed EntityManager. |
@PersistenceContexts | Used when multiple @PersistenceContexts are coded concurrently. | |
@PersistenceProperty | Sets up properties in the container--managed EntityManager. | |
@PersistenceUnit | Defines the persistence unit for the EntityManagerFactory. | |
@PersistenceUnits | Used when multiple @PersistenceUnits are coded concurrently. |
# For details on the callback method, see 6.15 How to specify the callback method in the uCosminexus Application Server Common Container Functionality Guide.