8.12 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 8.12.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 classification
Annotation name
Overview
Entity annotation
Indicates that the class is an entity.
Annotations related to the tables or columns
Specifies the mapping between the persistence field or the persistence property, and the columns of the database.
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.
Used when multiple @JoinColumn are coded concurrently.
This 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.
Specifies the column used as the external key, when binding with other tables.
Used when multiple @PrimaryKeyJoinColumn are coded concurrently.
Specifies a secondary table in the entity class.
Used when multiple @SecondaryTable are coded concurrently.
Specifies a primary table in the entity class.
@UniqueConstraint
If you want to generate CREATE statement 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
Specifies the compound primary key of a class that can be embedded.
Specifies the method for automatically generating and allotting a unique value to the primary key column.
Specifies the properties or fields of the primary key of the entity class.
Specifies the compound primary key class mapped to multiple fields or properties of the entity class.
Specifies the settings of the sequence generator that creates the primary key.
Specifies the settings of the generator that creates the primary key.
Lock annotation
Specifies the version field or the version property for using the optimistic lock functionality.
Annotations related to mapping
Indicates the type of mapping to the simplest database column.
Specifies an embedded class.
Specifies the persistence property or the persistence field indicating the instance value of the embedded class within the entity class at the embedding destination.
Specifies the persistence field or the persistence property as the enumeration type.
Specifies the persistence field or the persistence property of the large object type supported by the database.
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.
Specifies the order in which the collection is evaluated when the entity information is acquired.
Specifies in the persistence property or persistence field having the type that expresses the time (java.util.Date and java.util.Calendar).
Specifies the field or property of a non-persisting entity class, mapped superclass, or embedded class.
Annotations related to the relationship
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.
Indicates that the specified class has the ManyToOne relationship, and also specifies the relationship to the non-owner entity class.
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.
Indicates that the specified class has the OneToOne relationship, and also specifies the single relationship between entity classes.
Annotations related to inheritance and overriding
Overrides the settings used in the ManyToOne relationship or the OneToOne relationship specified in a mapped superclass and embedded class.
Used when multiple @AssociationOverride are coded concurrently.
Overrides the following mapping information:
-
Properties or fields specified by @Basic (or applied by default)
-
Properties or fields specified by @Id
Used when multiple @AttributeOverride are coded concurrently.
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.
Specifies the value of the column used for identification in the SINGLE_TABLE strategy or JOINED strategy.
Specifies the inheritance mapping strategy used in the entity class hierarchy.
Specifies a mapped superclass.
Annotations related to queries
Specifies the column for mapping the query results of an SQL to the entity class.
Specifies the entity class in which the query results of the SQL are to be mapped.
Specifies the field in which the query results of the SQL are to be mapped.
Used when multiple @NamedNativeQuery are coded concurrently.
Specifies a named query in the SQL.
Used when multiple @NamedQuery are coded concurrently.
Specifies a named query of JPQL.
Specifies a database-specific query hint.
Specifies the result set mapping of an SQL query.
Used when multiple @SqlResultSetMapping are coded concurrently.
Annotations related to event callback#
Specifies the callback listener class used in the entity class or mapped superclass.
This annotation excludes the default listener for the following classes:
-
Entity class
-
Mapped superclass
-
Subclass of the entity class or mapped superclass
This annotation excludes the superclass listener for the following classes:
-
Entity class
-
Mapped superclass
-
Subclass of the entity class or mapped superclass
This annotation indicates the callback method invoked after the SELECT statement is issued in the database.
This annotation indicates the callback method invoked after the INSERT statement is issued in the database.
This annotation indicates the callback method invoked after the DELETE statement is issued in the database.
This annotation indicates the callback method invoked after the UPDATE statement is issued in the database.
This annotation indicates the callback method invoked before the INSERT statement is issued in the database.
This annotation indicates the callback method invoked before the DELETE statement is issued in the database.
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
Defines the container-managed EntityManager.
Used when multiple @PersistenceContext are coded concurrently.
Sets up properties in the container-managed EntityManager.
Defines the persistence unit for the EntityManagerFactory.
Used when multiple @PersistenceUnit are coded concurrently.
- #
-
For details on the callback method, see 9.15 Procedure for specifying the callback method.
-
- Organization of this section