Jump to: navigation, search

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

m
Line 46: Line 46:
 
{{EclipseLink_JPA
 
{{EclipseLink_JPA
 
|previous=[[EclipseLink/UserGuide/JPA/Basic_JPA_Development/Entities/Creating_and_Configuring_Entities|Configuring Entities]]
 
|previous=[[EclipseLink/UserGuide/JPA/Basic_JPA_Development/Entities/Creating_and_Configuring_Entities|Configuring Entities]]
|next=    [[EclipseLink/UserGuide/JPA/Basic_JPA_Development/Entities/Ids/IdClass]]
+
|next=    [[EclipseLink/UserGuide/JPA/Basic_JPA_Development/Entities/Ids/IdClass|Specifying a Composite Primary Key For an Entity or Mapped Superclass Using @IdClass]]
 
|up=      [[EclipseLink/UserGuide/JPA/Basic_JPA_Development/Entities/Creating_and_Configuring_Entities|Configuring Entities]]
 
|up=      [[EclipseLink/UserGuide/JPA/Basic_JPA_Development/Entities/Creating_and_Configuring_Entities|Configuring Entities]]
 
|version=2.2.0 DRAFT}}
 
|version=2.2.0 DRAFT}}

Revision as of 12:46, 19 April 2011

EclipseLink JPA

link="http://wiki.eclipse.org/EclipseLink"
EclipseLink
Website
Download
Community
Mailing ListForumsIRC
Bugzilla
Open
Help Wanted
Bug Day
Contribute
Browse Source

Specifying an Entity's Primary Key Using @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, the entities Id must be set by the application, normally before the persist is called. A @GeneratedValue can be used to have EclipseLink generate the Id value.

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

Example: @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 11.1.18 "Id Annotation" in the JPA Specification.


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