Java Persistence API (JPA) Extensions Reference for EclipseLink, Release 2.5
  Go To Table Of Contents
 Search
 PDFComments
Comments


@UuidGenerator

Use @UuidGenerator to defines a primary key generator that may be referenced by name when a generator element is specified for the @GeneratedValue annotation. A UUID (universally unique identifier) generator may be specified on the entity class or on the primary key field or property.

The generator name is global to the persistence unit (that is, across all generator types).


Annotation Elements

Table 2-74 describes this annotation's elements.

Table 2-74 @UuidGenerator Annotation Elements

Annotation Element Description Default

name

Name of the UUID generator, must be unique for the persistence unit




Examples

Example 2-119 shows how to use this annotation.

Example 2-119 Using @UuidGenerator Annotation

@Entity
@UuidGenerator(name="EMP_ID_GEN")
public class Employee {
    @Id
    @GeneratedValue(generator="EMP_ID_GEN")
    private String id;
}

You can also specify the SessionCustomizer and configure the named sequence in your eclipselink-orm.xml file, as shown in Example 2-120.

Example 2-120 Using <generated-value> XML

<id name="id">
    <column name="PROJ_ID" />
    <generated-value generator="system-uuid"/>
</id>

You can also specify the named sequence at the persistence unit level (in the persistence.xml file) as shown in Example 2-121.

Example 2-121 Specifying Generator in persistence.xml

<property name="eclipselink.session.customizer" value="eclipselink.example.UUIDSequence"/>


See Also

For more information, see: