Hitachi

uCosminexus Application Server Compatibility Guide


9.12.3 Specifying the access methods for the entity class fields

Cosminexus JPA Provider accesses the entity class fields when the entity state is written to the database and the database state is read as an entity. The access method in this case is called access type. An access type includes properties and fields. You specify the access type in an annotation or in the O/R mapping file. The following table describes the access types and the specification methods.

Table 9‒17: Access types and specification methods

Access type

Description

Specification method

Annotation

O/R mapping file

Property

Method of obtaining the instance variable through the getter method.

Specify the annotation in the getter method of the field.

Specify PROPERTY in the <access> tag.

Field

Method of directly referencing the instance variable.

Specify an annotation in the field.

Specify FIELD in the <access> tag.

If the access type is a property, the property stored by the entity is called the persistence property. Also, when the access type is field, the entity field is called the persistence field.

Notes on the access types

Remember the following points when you specify the access types:

  • If the access type is a field, Cosminexus JPA Provider directly accesses the persistence field. The instance variable for which @Transient is not set is subject to persistence.

  • If the access type is property, Cosminexus JPA Provider uses the accessor method to obtain the persistence property value. The property for which @Transient is not set in the accessor method is subject to persistence.

  • If the access type is property, you cannot set the mapping annotation in the setter method. In the case of Cosminexus JPA Provider, the mapping annotation set in the setter method is ignored.

  • You cannot set the mapping annotation in the field and property in which @Transient is specified or <transient> tag is specified in the O/R mapping file. If the mapping annotation is set, an exception occurs when the application starts.

  • Set the accessor method of the property to public or protected. This is prohibited in the JPA specifications, but is not checked with Cosminexus JPA. Also, even in the case of private, an exception does not occur.

  • If the mapping annotation is applied to the accessor methods of both, the persistence field and the persistence property, all the annotations set in the accessor method of the persistence property are ignored.