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

From Eclipsepedia

Jump to: navigation, search
(New page: {{EclipseLink_UserGuide |info=y |toc=n |eclipselink=y |eclipselinktype=JPA |api=y |apis= *[http://www.eclipse.org/eclipselink/api/latest/javax/persistence/GeneratedValue.html @GeneratedVal...)
 
(Example: Using)
 
(2 intermediate revisions by one user not shown)
Line 10: Line 10:
 
}}
 
}}
 
=@UuidGenerator=
 
=@UuidGenerator=
You can use the <code>@UuidGenerator</code> 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 <tt>String</tt> (32 bytes) or a <tt>byte[]</tt> (16 bytes).  UUIDs are useful in distributed architectures as they do not require a single id generator node.
+
You can use the <code>@UuidGenerator</code> 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 <tt>String</tt> (32 bytes) or a <tt>byte[]</tt> (16 bytes).  UUIDs are useful in distributed architectures as they do not require a single generation point.
  
 
{{EclipseLink_AttributeTable
 
{{EclipseLink_AttributeTable
Line 23: Line 23:
 
}}
 
}}
  
 
The following example shows how to use this annotation to specify the allocation size for the <tt>SEQUENCE</tt> primary key generator named <tt>Emp_Seq</tt>.
 
  
 
======'' Example: @UuidGenerator''======
 
======'' Example: @UuidGenerator''======
Line 60: Line 58:
  
 
{{EclipseLink_JPA
 
{{EclipseLink_JPA
|previous=[[EclipseLink/UserGuide/JPA/Basic_JPA_Development/Entities/Ids/TableGenerator|@SequenceGenerator]]
+
|previous=[[EclipseLink/UserGuide/JPA/Basic_JPA_Development/Entities/Ids/SequenceGenerator|@SequenceGenerator]]
 
|next=    [[EclipseLink/UserGuide/JPA/Basic JPA Development/Entities/Table|@Table]]
 
|next=    [[EclipseLink/UserGuide/JPA/Basic JPA Development/Entities/Table|@Table]]
 
|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.4 DRAFT}}
 
|version=2.4 DRAFT}}

Latest revision as of 11:45, 28 June 2012

EclipseLink JPA

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

[edit] @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


[edit] Example: @UuidGenerator
 @Entity
 public class Employee implements Serializable {
     ...
     @Id
     @UuidGenerator(name="UUID")
     @GeneratorValue(generator="UUID")
     @Column(name="EMP_ID")
     public String getId() {
         return id;
     }
     ...
 }
[edit] 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...