{"id":20,"date":"2008-06-15T12:57:01","date_gmt":"2008-06-15T07:27:01","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=20"},"modified":"2016-12-19T14:35:16","modified_gmt":"2016-12-19T09:05:16","slug":"how-to-use-table-per-subclass-inheritance-strategy-instead-of-table-per-hierarchy","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/how-to-use-table-per-subclass-inheritance-strategy-instead-of-table-per-hierarchy\/","title":{"rendered":"How to use table-per-subclass inheritance strategy instead of table-per-hierarchy"},"content":{"rendered":"<p>In this blog I want to share how to use <strong>table per sub-class<\/strong> instead of table per hierarchy, which is the <a href=\"http:\/\/www.tothenew.com\/blog\/how-to-make-bootstraping-environment-specific-in-a-grails-app\/\">default mechanism provided by Grails<\/a>.<code><\/code> I am not sure why Grails chose to use &#8220;table-per-hierarchy&#8217;. I always find it difficult to understand the table structure produced by &#8220;<strong>table-per-hierarchy<\/strong>&#8220;. 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 <code>\"Not Null\"<\/code> constraint applied to them at the db level.<\/p>\n<p>If you are like me and prefer to use a <strong>table-per-subclass <code><\/code><\/strong>inheritance strategy, it can be easily achieved using fantastic Grails GORM DSL.<\/p>\n<p>Simply include the following code in all your Grails domain classes.<\/p>\n<pre lang=\"groovy\">   static mapping = {\r\n   tablePerHierarchy false\r\n}<\/pre>\n<p>This can be simply specified at the root class level and does-not need to be specified for all sub-classes in the hierarchy.<\/p>\n<p>Hope this helps.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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 &#8220;table-per-hierarchy&#8217;. I always find it difficult to understand the table structure produced by &#8220;table-per-hierarchy&#8220;. Moreover, it makes things difficult for [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":16},"categories":[7],"tags":[29,4840],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/20"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=20"}],"version-history":[{"count":0,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/20\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=20"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=20"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=20"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}