MappedSuperclass Alternatives in Grails

眉间皱痕 提交于 2019-11-29 05:18:35

OK, did a little bit more searching and I answered my own question :)

Essentially, it's as simple as declaring the MappedSuperclass as abstract and grails will not create a table for it. I realized by re-reading the manual (RTFM basically...works wonders): "GORM supports inheritance both from abstract base classes and concrete persistent GORM entities." I.e. concrete classes are persistent, so abstract ones are not. Pays to read more carefully.

E.g.

abstract class Auditable {
    Date dateCreated
    Date lastUpdated
}

class Book extends Auditable {
    String title
    String description
}

Only the book table will be created and it will have the

date_created

and

last_updated

columns. Furthermore, as an added bonus, the dateCreated and lastUpdated properties are auto time-stamped by Grails.

Hope this helps others.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!