Hitachi

uCosminexus Application Server Compatibility Guide


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

@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 @JoinColumn are coded concurrently.

@JoinTable

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.

@PrimaryKeyJoinColumn

Specifies the column used as the external key, when binding with other tables.

@PrimaryKeyJoinColumns

Used when multiple @PrimaryKeyJoinColumn are coded concurrently.

@SecondaryTable

Specifies a secondary table in the entity class.

@SecondaryTables

Used when multiple @SecondaryTable are coded concurrently.

@Table

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

@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 @AssociationOverride are coded concurrently.

@AttributeOverride

Overrides the following mapping information:

  • Properties or fields specified by @Basic (or applied by default)

  • Properties or fields specified by @Id

@AttributeOverrides

Used when multiple @AttributeOverride 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 @NamedNativeQuery are coded concurrently.

@NamedNativeQuery

Specifies a named query in the SQL.

@NamedQueries

Used when multiple @NamedQuery 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 @SqlResultSetMapping 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:

  • Entity class

  • Mapped superclass

  • Subclass of the entity class or mapped superclass

@ExcludeSuperclassListeners

This annotation excludes the superclass listener for the following classes:

  • Entity class

  • Mapped superclass

  • Subclass of the entity class or mapped superclass

@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 @PersistenceContext are coded concurrently.

@PersistenceProperty

Sets up properties in the container-managed EntityManager.

@PersistenceUnit

Defines the persistence unit for the EntityManagerFactory.

@PersistenceUnits

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