"Fossies" - the Fresh Open Source Software Archive

Member "grails-core-5.2.4/grails-docs/src/test/resources/docs/ref/Database Mapping/type.html" (14 Sep 2022, 61847 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)

type

Purpose

Configures the Hibernate type for a particular property.

Examples

Changing to a text type (CLOB or TEXT depending on database dialect):

class Book {

    String title

    static mapping = {
        title type: "text"
    }
}

User types with multiple columns:

class Book {
    ...
    MonetaryAmount amount

    static mapping = {
        amount type: MonetaryUserType, {
            column name: "value"
            column name: "currency", sqlType: "char", length: 3
        }
    }
}

Description

Usage: association_name(type:string/class)

Hibernate will attempt to automatically select the appropriate database type from the field typed based on configuration in the Dialect class that is being used. But you can override the defaults if necessary. For example String values are mapped by default to varchar(255) columns. To store larger String values you can use a text type instead:

static mapping = {
    title type: "text"
}

Hibernate also has the concept of custom UserType implementations. In this case you specify the UserType class. If the UserType maps to multiple columns you may need to specify a mapping for each column:

static mapping = {
    amount type: MonetaryUserType, {
        column name: "value"
        column name: "currency", sqlType: "char", length: 3
    }
}