Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.
Difference between revisions of "EclipseLink/UserGuide/JPA/Basic JPA Development/Configuration/JPA/Annotations"
m (New page: =Annotations= {{EclipseLink_JPA |previous=persistence.xml |next=[[EclipseLink/UserGuide/JPA/Basic J...) |
m (→Annotations) |
||
Line 1: | Line 1: | ||
=Annotations= | =Annotations= | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | A metadata annotation represents a Java language feature that lets you attach structured and typed metadata to the source code. Annotations alone are sufficient for the metadata specification–you do not need to use XML. Annotations for object relational mapping are in the <tt>javax.persistence</tt> package. For more information and examples, see | ||
+ | |||
+ | |||
+ | {{EclipseLink_Spec | ||
+ | |link=http://jcp.org/en/jsr/detail?id=220 | ||
+ | |section=Chapter 8 "Metadata Annotations" | ||
+ | }} | ||
+ | |||
+ | An object relational mapping XML file is optional. If you choose to provide one, then it should contain mapping information for the classes listed in it. The persistence provider loads an [[EclipseLink/UserGuide/JPA/Basic JPA Development/Configuration/JPA/orm.xml|orm.xml file]] (or other mapping file) as a resource. If you provide a mapping file, the classes and mapping information specified in the mapping file will be used. The XML mapping metadata may combine with and override annotation metadata. | ||
+ | {{EclipseLink_Spec | ||
+ | |link=http://jcp.org/en/jsr/detail?id=220 | ||
+ | |section=Section 10.1 "XML Overriding Rules" | ||
+ | }} | ||
+ | |||
+ | |||
+ | ==Advantages and Disadvantages of Using Annotations== | ||
+ | Metadata annotations are relatively simple to use and understand. They provide in-line metadata located with the code that this metadata is describing–you do not need to replicate the source code context of where the metadata applies. | ||
+ | |||
+ | On the other hand, annotations unnecessarily couple the metadata to the code. Thus, changes to metadata require changing the source code. | ||
+ | |||
Revision as of 14:22, 16 June 2010
Annotations
A metadata annotation represents a Java language feature that lets you attach structured and typed metadata to the source code. Annotations alone are sufficient for the metadata specification–you do not need to use XML. Annotations for object relational mapping are in the javax.persistence package. For more information and examples, see
For more information, see Chapter 8 "Metadata Annotations" in the JPA Specification.
An object relational mapping XML file is optional. If you choose to provide one, then it should contain mapping information for the classes listed in it. The persistence provider loads an orm.xml file (or other mapping file) as a resource. If you provide a mapping file, the classes and mapping information specified in the mapping file will be used. The XML mapping metadata may combine with and override annotation metadata.
For more information, see Section 10.1 "XML Overriding Rules" in the JPA Specification.
Advantages and Disadvantages of Using Annotations
Metadata annotations are relatively simple to use and understand. They provide in-line metadata located with the code that this metadata is describing–you do not need to replicate the source code context of where the metadata applies.
On the other hand, annotations unnecessarily couple the metadata to the code. Thus, changes to metadata require changing the source code.