////
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements.  See the NOTICE file
distributed with this work for additional information
regarding copyright ownership.  The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License.  You may obtain a copy of the License at

https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied.  See the License for the
specific language governing permissions and limitations
under the License.
////


== type



=== Purpose


Configures the Hibernate type for a particular property.


=== Examples


Changing to an unbounded text type (e.g. `TEXT`, `LONGTEXT` or `CLOB` depending on database dialect):

[source,groovy]
----
class Book {

    String title

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

User types with multiple columns:

[source,groovy]
----
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:

[source,groovy]
----
static mapping = {
    title type: "text"
}
----

NOTE: `type: "text"` does not map to a literal SQL type named `text`. GORM asks Hibernate to resolve the dialect's own unbounded large-character type, which is `text` on PostgreSQL and H2, `longtext` on MySQL and MariaDB, and `CLOB` on Oracle. Every `Dialect` shipped with Hibernate defines this mapping, so the resolved column is always unbounded regardless of which of these databases you use — you don't need to (and can't) choose the literal SQL type name yourself.

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:

[source,groovy]
----
static mapping = {
    amount type: MonetaryUserType, {
        column name: "value"
        column name: "currency", sqlType: "char", length: 3
    }
}
----
