Skip to main content

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.

Jump to: navigation, search

EclipseLink/UserGuide/JPA/Basic JPA Development/Entities/Ids/UuidGenerator

< EclipseLink‎ | UserGuide‎ | JPA‎ | Basic JPA Development
Revision as of 11:45, 28 June 2012 by James.sutherland.oracle.com (Talk | contribs) (Example: Using)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

EclipseLink JPA

Eclipselink-logo.gif
EclipseLink
Website
Download
Community
Mailing ListForumsIRCmattermost
Issues
OpenHelp WantedBug Day
Contribute
Browse Source

@UuidGenerator

You can use the @UuidGenerator to generate an object's Id based on a Universally Unique IDentifier (UUID). A UUID is a globally unique id. A UUID does not require database access, so is efficient to generate, but is a large value, so requires more storage than a numeric id. A UUID can be stored as a String (32 bytes) or a byte[] (16 bytes). UUIDs are useful in distributed architectures as they do not require a single generation point.

@UuidGeneratorAttributes
Attribute Description Default Required?
name The name of the generator must match the name of a GeneratedValue. Yes


Example: @UuidGenerator
 @Entity
 public class Employee implements Serializable {
     ...
     @Id
     @UuidGenerator(name="UUID")
     @GeneratorValue(generator="UUID")
     @Column(name="EMP_ID")
     public String getId() {
         return id;
     }
     ...
 }
Example: Using <sequence-generator>
<entity class="Employee">
    <attributes>
        <id name="id">
            <column name="EMP_ID"/>
            <generated-value generator="UUID"/>
            <uuid-generator name="UUID"/>
        </id>
        ...
    </attributes>
</entity>


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

Copyright © Eclipse Foundation, Inc. All Rights Reserved.