Notice: This Wiki is now read only and edits are no longer 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/Entities/Ids/Id"
m (Undo revision 207000 by Rick.sapir.oracle.com (Talk)) |
m (→@Id) |
||
Line 3: | Line 3: | ||
For each entity, you must designate at least one of the following: | For each entity, you must designate at least one of the following: | ||
− | * one <tt>@Id</tt> | + | * one <tt>@Id</tt>, or |
− | * one <tt>[[ | + | * one <tt>[[EclipseLink/UserGuide/JPA/Basic JPA Development/Mapping/Entity/EmbeddedId|@EmbeddedId]]</tt>, or |
− | * multiple <tt>@Id</tt> and an <tt>[[ | + | * multiple <tt>@Id</tt> and an <tt>[[EclipseLink/UserGuide/JPA/Basic JPA Development/Mapping/Entity/IdClass|@IdClass]]</tt> |
{{EclipseLink_Note | {{EclipseLink_Note | ||
Line 39: | Line 39: | ||
{{EclipseLink_JPA | {{EclipseLink_JPA | ||
|previous=[[EclipseLink/UserGuide/JPA/Basic JPA Development/Mapping/Entity|Entity]] | |previous=[[EclipseLink/UserGuide/JPA/Basic JPA Development/Mapping/Entity|Entity]] | ||
− | |next=[[EclipseLink/UserGuide/JPA/Basic JPA Development/Mapping/ | + | |next= [[EclipseLink/UserGuide/JPA/Basic JPA Development/Mapping/Entity/IdClass|@IdClass]] |
− | |up=[[EclipseLink/UserGuide/JPA/Basic JPA Development/Mapping/Entity|Entity]]}} | + | |up= [[EclipseLink/UserGuide/JPA/Basic JPA Development/Mapping/Entity|Entity]]}} |
Revision as of 08:46, 17 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:
- one @Id, or
- one @EmbeddedId, or
- multiple @Id and an @IdClass
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.
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).
For more information, see Section 9.1.8 "Id Annotation" in the JPA Specification.
Entity | @IdClass | |
EclipseLink Home
JPA User Guide: Table of Contents, Search |
||
How to contribute to this guide... |