8.6.3 Overriding the @PersistenceContext definition using the DD
If the <persistence-context-ref> tag is defined in the DD when @PersistenceContext is mentioned in the application, the contents defined in the annotation are overwritten by the contents defined in the DD. In this case, the mapping between the annotations and DD is determined with the mapping between the name attribute of @PersistenceContext and the <persistence-context-ref-name> tag present under the <persistence-context-ref> tag of the DD. Note that even if the name attribute is not explicitly specified in @PersistenceContext, the name attribute contains the default value.
The precautions to be taken when the attributes specified in @PersistenceContext are overridden with the DD tags are as follows:
- Organization of this subsection
(1) <persistence-unit-name> tag and unitName attribute
The <persistence-unit-name> tag of the DD overrides the unitName attribute of @PersistenceContext. Normally, if you change the persistence unit name, the application stops operating, so take care when you define the DD and annotations.
(2) <persistence-context-type> tag and type attribute
The <persistence-context-type> tag of the DD overrides the type attribute of @PersistenceContext. Normally, if you change the life cycle type of the persistence context, the application stops operating, so take care when you define the DD and annotations.
(3) <persistence-property> tag and properties attribute
The properties specified in the <persistence-property> tag of the DD are added to the properties specified in the properties attribute of @PersistenceContext. However, if the property name is the same, the property value is overridden.
(4) <injection-target> tag
The injection target cannot be overridden. Note that when the <injection-target> tag is coded in the DD, accurately specify the fields and methods in which @PersistenceContext is added.