How to use table-per-subclass inheritance strategy instead of table-per-hierarchy
In this blog I want to share how to use table per sub-class instead of table per hierarchy, which is the default mechanism provided by Grails. I am not sure why Grails chose to use “table-per-hierarchy’. I always find it difficult to understand the table structure produced by “table-per-hierarchy“. Moreover, it makes things difficult for other non-grails application which need to read data from the data database. Another disadvantage is that columns cannot have a
"Not Null"
constraint applied to them at the db level.
If you are like me and prefer to use a table-per-subclass inheritance strategy, it can be easily achieved using fantastic Grails GORM DSL.
Simply include the following code in all your Grails domain classes.
static mapping = {
tablePerHierarchy false
}
This can be simply specified at the root class level and does-not need to be specified for all sub-classes in the hierarchy.
Hope this helps.
Four more years under socialists and everyone will have the same insurance.
Can you explain the differences between the two strategies?
thanks!