2.7 javax.persistence package

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.

Precautions when specifying an annotation
  • With the Cosminexus JPA, the annotations included in the javax.persistence package are not supported in the attributes related to the DDL output functionality.
  • When specifying the same column name more than once in an annotation, arrange the upper case and lower case characters.
  • If field names or method names are allocated in the column name, character strings are considered as upper case characters strings and used with Cosminexus JPA. If you want to specify a column name in the supported annotation, use upper case characters.
  • The access type is decided according to the location at which the annotation is provided. However, if the access type exists in both, the field and property, the settings of the field will be enabled.
  • The property name is decided as follows depending on the character string acquired by removing get or set (is) from the access method:
    - If the first two characters are in upper case, the string is used as it is.
    - If the first two characters are not in upper case, the first character is converted into lower case, and the string is used.
    - For a single character, the first character is converted into lower case, and the string is used.
List of annotations
Annotation classificationAnnotation nameOverview
Entity annotation@EntityIndicates that the class is an entity.
Annotations related to the tables or columns@ColumnSpecifies the mapping between the persistence field or the persistence property, and the columns of the database.
@JoinColumnSpecifies 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.
@JoinColumnsUsed when multiple @JoinColumns are coded concurrently.
@JoinTableThis annotation specifies the binding table set up in the following classes:
  • Owner side class when ManyToMany relationship is specified.
  • Class with single-sided OneToMany relationship.
@PrimaryKeyJoinColumnSpecifies the column used as the external key, when binding with other tables.
@PrimaryKeyJoinColumnsUsed when multiple @PrimaryKeyJoinColumns are coded concurrently.
@SecondaryTableSpecifies a secondary table in the entity class.
@SecondaryTablesUsed when multiple @SecondaryTables are coded concurrently.
@TableSpecifies a primary table in the entity class.
@UniqueConstraintIf 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@EmbeddedIdSpecifies the compound primary key of a class that can be embedded.
@GeneratedValueSpecifies the method for automatically generating and allotting a unique value to the primary key column.
@IdSpecifies the properties or fields of the primary key of the entity class.
@IdClassSpecifies the compound primary key class mapped to multiple fields or properties of the entity class.
@SequenceGeneratorSpecifies the settings of the sequence generator that creates the primary key.
@TableGeneratorSpecifies the settings of the generator that creates the primary key.
Lock annotation@VersionSpecifies the version field or the version property for using the optimistic lock functionality.
Annotations related to mapping@BasicIndicates the type of mapping to the simplest database column.
@EmbeddableSpecifies an embedded class.
@EmbeddedSpecifies the persistence property or the persistence field indicating the instance value of the embedded class within the entity class at the embedding destination.
@EnumeratedSpecifies the persistence field or the persistence property as the enumeration type.
@LobSpecifies the persistence field or the persistence property of the large object type supported by the database.
@MapKeySpecifies 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.
@OrderBySpecifies the order in which the collection is evaluated when the entity information is acquired.
@TemporalSpecifies in the persistence property or persistence field having the type that expresses the time (java.util.Date and java.util.Calendar).
@TransientSpecifies the field or property of a non--persisting entity class, mapped superclass, or embedded class.
Annotations related to the relationship@ManyToManyIndicates 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.
@ManyToOneIndicates that the specified class has the ManyToOne relationship, and also specifies the relationship to the non--owner entity class.
@OneToManyIndicates 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.
@OneToOneIndicates that the specified class has the OneToOne relationship, and also specifies the single relationship between entity classes.
Annotations related to inheritance and overriding@AssociationOverrideOverrides the settings used in the ManyToOne relationship or the OneToOne relationship specified in a mapped superclass and embedded class.
@AssociationOverridesUsed when multiple @AssociationOverrides are coded concurrently.
@AttributeOverrideOverrides the following mapping information:
  • Properties or fields specified by @Basic (or applied by default)
  • Properties or fields specified by @Id
@AttributeOverridesUsed when multiple @ElementOverrides are coded concurrently.
@DiscriminatorColumnSpecifies 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.
@DiscriminatorValueSpecifies the value of the column used for identification in the SINGLE_TABLE strategy or JOINED strategy.
@InheritanceSpecifies the inheritance mapping strategy used in the entity class hierarchy.
@MappedSuperclassSpecifies a mapped superclass.
Annotations related to queries@ColumnResultSpecifies the column for mapping the query results of an SQL to the entity class.
@EntityResultSpecifies the entity class in which the query results of the SQL are to be mapped.
@FieldResultSpecifies the field in which the query results of the SQL are to be mapped.
@NamedNativeQueriesUsed when multiple @NamedNativeQueries are coded concurrently.
@NamedNativeQuerySpecifies a named query in the SQL.
@NamedQueriesUsed when multiple @NamedQueries are coded concurrently.
@NamedQuerySpecifies a named query of JPQL.
@QueryHintSpecifies a database--specific query hint.
@SqlResultSetMappingSpecifies the result set mapping of an SQL query.
@SqlResultSetMappingsUsed when multiple @SqlResultSetMappings are coded concurrently.
Annotations related to event callback#@EntityListenersSpecifies the callback listener class used in the entity class or mapped superclass.
@ExcludeDefaultListenersThis annotation excludes the default listener for the following classes:
  • Entity class
  • Mapped superclass
  • Subclass of the entity class or mapped superclass
@ExcludeSuperclassListenersThis annotation excludes the superclass listener for the following classes:
  • Entity class
  • Mapped superclass
  • Subclass of the entity class or mapped superclass
@PostLoadThis annotation indicates the callback method invoked after the SELECT statement is issued in the database.
@PostPersistThis annotation indicates the callback method invoked after the INSERT statement is issued in the database.
@PostRemoveThis annotation indicates the callback method invoked after the DELETE statement is issued in the database.
@PostUpdateThis annotation indicates the callback method invoked after the UPDATE statement is issued in the database.
@PrePersistThis annotation indicates the callback method invoked before the INSERT statement is issued in the database.
@PreRemoveThis annotation indicates the callback method invoked before the DELETE statement is issued in the database.
@PreUpdateThis annotation indicates the callback method invoked before the UPDATE statement is issued in the database.
Annotations related to the reference of EntityManager and EntityManagerFactory@PersistenceContextDefines the container--managed EntityManager.
@PersistenceContextsUsed when multiple @PersistenceContexts are coded concurrently.
@PersistencePropertySets up properties in the container--managed EntityManager.
@PersistenceUnitDefines the persistence unit for the EntityManagerFactory.
@PersistenceUnitsUsed 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.


Organization of this section
2.7.1 @AssociationOverride
2.7.2 @AssociationOverrides
2.7.3 @AttributeOverride
2.7.4 @AttributeOverrides
2.7.5 @Basic
2.7.6 @Column
2.7.7 @ColumnResult
2.7.8 @DiscriminatorColumn
2.7.9 @DiscriminatorValue
2.7.10 @Embeddable
2.7.11 @Embedded
2.7.12 @EmbeddedId
2.7.13 @Entity
2.7.14 @EntityListeners
2.7.15 @EntityResult
2.7.16 @Enumerated
2.7.17 @ExcludeDefaultListeners
2.7.18 @ExcludeSuperclassListeners
2.7.19 @FieldResult
2.7.20 @GeneratedValue
2.7.21 @Id
2.7.22 @IdClass
2.7.23 @Inheritance
2.7.24 @JoinColumn
2.7.25 @JoinColumns
2.7.26 @JoinTable
2.7.27 @Lob
2.7.28 @ManyToMany
2.7.29 @ManyToOne
2.7.30 @MapKey
2.7.31 @MappedSuperclass
2.7.32 @NamedNativeQueries
2.7.33 @NamedNativeQuery
2.7.34 @NamedQueries
2.7.35 @NamedQuery
2.7.36 @OneToMany
2.7.37 @OneToOne
2.7.38 @OrderBy
2.7.39 @PersistenceContext
2.7.40 @PersistenceContexts
2.7.41 @PersistenceProperty
2.7.42 @PersistenceUnit
2.7.43 @PersistenceUnits
2.7.44 @PostLoad
2.7.45 @PostPersist
2.7.46 @PostRemove
2.7.47 @PostUpdate
2.7.48 @PrePersist
2.7.49 @PreRemove
2.7.50 @PreUpdate
2.7.51 @PrimaryKeyJoinColumn
2.7.52 @PrimaryKeyJoinColumns
2.7.53 @QueryHint
2.7.54 @SecondaryTable
2.7.55 @SecondaryTables
2.7.56 @SequenceGenerator
2.7.57 @SqlResultSetMapping
2.7.58 @SqlResultSetMappings
2.7.59 @Table
2.7.60 @TableGenerator
2.7.61 @Temporal
2.7.62 @Transient
2.7.63 @Version
2.7.64 Correspondence between the annotations and O/R mapping