Jump to: navigation, search

Difference between revisions of "EclipseLink/UserGuide/JPA/Basic JPA Development/Entities/Ids/Id"

m (@Id)
m (@Id)
Line 14: Line 14:
 
The <tt>@Id</tt> annotation does not have attributes.
 
The <tt>@Id</tt> annotation does not have attributes.
  
By default, EclipseLink persistence provider chooses the most appropriate primary key generator (see [[#@GeneratedValue|@GeneratedValue]]) and is responsible for managing primary key values: you do not need to take any further action if you are satisfied with the persistence provider's default key generation mechanism.
+
By default, EclipseLink persistence provider chooses the most appropriate primary key generator (see [[EclipseLink/UserGuide/JPA/Basic JPA Development/Mapping/Entity/GeneratedValue|@GeneratedValue]]) and is responsible for managing primary key values: you do not need to take any further action if you are satisfied with the persistence provider's default key generation mechanism.
  
 
This example shows how to use this annotation to designate the persistent field <tt>empID</tt> as the primary key of the <tt>Employee</tt> table.
 
This example shows how to use this annotation to designate the persistent field <tt>empID</tt> as the primary key of the <tt>Employee</tt> table.
  
<span id="Example 18-2"></span>
+
<span id="Example_Usage_of_@Id_Annotation"></span>
 
''''' Usage of @Id Annotation'''''
 
''''' Usage of @Id Annotation'''''
 
<source lang="java">
 
<source lang="java">
Line 29: Line 29:
 
</source>
 
</source>
  
The <tt>@Id</tt> annotation supports the use of EclipseLink converters (see [[Using%20EclipseLink%20JPA%20Extensions%20(ELUG)#Using EclipseLink JPA Converters|Using EclipseLink JPA Converters]]).
+
The <tt>@Id</tt> annotation supports the use of EclipseLink converters (see [[EclipseLink/UserGuide/JPA/Basic_JPA_Development/Mapping/Basic_Mappings/Default_Conversions_and_Converters|Using EclipseLink JPA Converters]]).
  
For more information and examples, see Section 9.1.8 "Id Annotation" of the [http://jcp.org/en/jsr/detail?id=220 JPA Specification].
+
{{EclipseLink_Spec
 +
|link=http://jcp.org/en/jsr/detail?id=220
 +
|section=Section 9.1.8 "Id Annotation"}}
  
  

Revision as of 12:04, 16 June 2010

@Id

Use the @Id annotation to designate one or more persistent fields or properties as the entity's primary key.

For each entity, you must designate at least one of the following:

Elug note icon.png

Note: The last option in the preceding list – @Id and @IdClass combination – is applicable to composite primary key configuration.


The @Id annotation does not have attributes.

By default, EclipseLink persistence provider chooses the most appropriate primary key generator (see @GeneratedValue) and is responsible for managing primary key values: you do not need to take any further action if you are satisfied with the persistence provider's default key generation mechanism.

This example shows how to use this annotation to designate the persistent field empID as the primary key of the Employee table.

Usage of @Id Annotation

 @Entity
 public class Employee implements Serializable {
     @Id
     private int empID;
     ...
 }

The @Id annotation supports the use of EclipseLink converters (see Using EclipseLink JPA Converters).

Elug javaspec icon.gif

For more information, see Section 9.1.8 "Id Annotation" in the JPA Specification.


Eclipselink-logo.gif
Version: DRAFT
Other versions...