Reputation: 21
Hi all following is the situation I have an abstract class AbstractProfile and one concrete class GoogleProfile
abstract class AbstractProfile {
.....
}
class GoogleProfile extends AbstractProfile {
......
}
I am using grails but gorm is not inserting table for google profile current gorm is inserting table for only AbstractProfile class please help Thanks in advance
Upvotes: 2
Views: 2201
Reputation: 322
I did some digging and found out that starting on grails 2.3 you have the following mapping option:
tablePerConcreteClass true
It seems the documentation (even for version 2.4) hasn't been updated regarding this yet.
Upvotes: 3
Reputation: 1129
Following up on Михаил's great answer, two separate things worked for me.
This worked best for me because both the constraints from the base class and the subclass were applied. Having not null columns in the subclasses was important for my use case. However, it appears that only the mapping block from the subclass is used.
tablePerConcreteClass true
An advantage here is it allows an index to be declared in the BaseDomain class that then appears in each of the subclass tables, ie both the mapping blocks from the base class and subclass are used. Only the constraints in the base class appear to be used.
abstract class BaseDomain {
static mapping = {
tablePerHierarchy false // avoid creating the base_domain table
tablePerConcreteClass true
id generator: 'increment' // https://jira.grails.org/browse/GRAILS-10849
someColumnInBaseDomain index: true // index this column in each subclass table
}
}
Upvotes: 0
Reputation: 346
You can use this :
abstract class BaseDomain {
static mapping = {
tablePerConcreteClass true
id generator: 'increment'
version false
}
}
Upvotes: 1
Reputation: 2975
Grails 2.0 persists abstract classes. In order to enable an individual table to the extending class, you need to specify:
static mapping = {
tablePerHierarchy false
}
to the abstract class. Otherwise the whole hierarchy will "live" in the same table.
Upvotes: 0