"Fossies" - the Fresh Open Source Software Archive

Member "grails-core-5.2.4/grails-docs/src/test/resources/docs/ref/Database Mapping/id.html" (14 Sep 2022, 62767 Bytes) of package /linux/www/grails-core-5.2.4.tar.gz:


Caution: In this restricted "Fossies" environment the current HTML page may not be correctly presentated and may have some non-functional links. You can here alternatively try to browse the pure source code or just view or download the uninterpreted raw source code. If the rendering is insufficient you may try to find and view the page on the grails-core-5.2.4.tar.gz project site itself.

(Quick Reference)

id

Purpose

Customizes the way the identifier for a domain class is generated

Examples

class Book {
    String id
    String title
    static mapping = {
        id generator: 'uuid'
    }
}

Description

Usage: id(map)

Arguments:

  • generator (optional) - The name of the generator to use. Can be increment, identity, sequence, seqhilo, uuid, uuid.hex, assigned, select, foreign, sequence-identity, enhanced-sequence or enhanced-table. See Hibernate reference documentation for more information.

hilo generator was removed in Hibernate 5. See Hibernate 5 Migration Guide.
  • composite (optional) - Takes a list of property names to use that form the composite identifier

  • name (optional) - The property name to use as the identifier

  • params (optional) - Any parameters to pass to the defined identity generator

  • column (optional) - The column name to map the identifier to. The remaining column definition properties are also available.

By default GORM uses the native strategy to generate a database identifier for each entity (typically an auto-incrementing column or a sequence). You can alter this with the id methods generator argument:

static mapping = {
    id generator: 'uuid'
}

You can also use the method to define a composite identifier:

static mapping = {
    id composite: ['title', 'author']
}

or change the name of the property that defines the identifier:

static mapping = {
    id name: 'title'
}

You can also alter the column definition:

static mapping = {
    id column: 'book_id', type: 'integer'
}

See the section on Custom Database Identity in the user guide for more information.