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 type based from a properties java.lang.Class
. However, this choice is not always appropriate. For example String
values are by default mapped to varchar(255)
columns. If you want 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 need to specify the UserType
class. If the UserType
maps to multiple columns you may need to specify mapping for each column:static mapping = {
amount type: MonetaryUserType, {
column name: "value"
column name: "currency", sqlType: "char", length: 3
}
}