在过去的许多项目中,我使用 这种 JPA/Hibernate 方法可以向系统添加审核功能。 它非常有效且不引人注目。
是否有 Grails @MappedSuperclass 替代方案(缺少用 Java 而不是 Groovy 编码域模型对象)? 如何在不为其创建表的情况下以每个子类一个表的方法声明父类? 我已阅读 GORM 文档 (5.2.3 GORM 中的继承),但除了每个层次结构表与每个子类表的讨论之外,我没有找到任何有关如何执行此操作的详细信息。
或者,在 Grails 中实现此类审计的推荐方法是什么?
In many past projects, I used this JPA / Hibernate approach to add auditing capabilities to a system. It's very effective and unobtrusive.
Is there a Grails @MappedSuperclass alternative (short of coding domain model objects in Java instead of Groovy)? How can one declare a parent class in a table-per-subclass approach without having a table created for it? I've read the GORM documentation (5.2.3 Inheritance in GORM) but besides the table-per-hierarchy vs. table-per-subclass discussion, I did not find any details on how to do this.
Alternatively, what is the recommended way to achieve this type of auditing in Grails?
发布评论
评论(1)
本质上,就像将
MappedSuperclass
声明为abstract
一样简单,Grails 不会为它创建表。 我通过 re 实现-阅读手册:例如,
只会创建图书表,并且它将具有
date_created
和last_updated
列。 此外,作为额外的好处,dateCreated
和lastUpdated
属性是 Grails 的自动时间戳。Essentially, it's as simple as declaring the
MappedSuperclass
asabstract
and Grails will not create a table for it. I realized by re-reading the manual:E.g.
Only the book table will be created and it will have the
date_created
andlast_updated
columns. Furthermore, as an added bonus, thedateCreated
andlastUpdated
properties are auto time-stamped by Grails.