Inside your Domain class:
static mapping={
field1 index:'MY_INDEX'
field2 index:'MY_INDEX'
}
that is simple enough. It gets ugly if you want to create multiple indexes for multiple different columns.
See the DomainIndexHelper.groovy
If you have a A > B
hierarchy of domain classes, then the fields in A
are apparently
not visible in the mapping section of B
class A{
String field1
}
class B extends A{
String field2
static mapping={
field1 index:'MY_INDEX' //doesn't work
field2 index:'MY_INDEX'
}
}
The solution is to define the index name for the fields in A mapping:
class A{
String field1
static mapping={
field1 index:'MY_INDEX'
}
}
class B extends A{
String field2
static mapping={
field2 index:'MY_INDEX'
}
}
Grails implicitly adds a class
field to the table, if you are using "table-per-hierarchy".
This means that basically every query for that table includes a where class = 'B'
clause,
but unfortunately, it appears that implicit field is not available to index defintions within
the mapping
clause :(((.
See: issue#6815