MappedSuperclass在Grails 2.0中的替代品 [英] MappedSuperclass Alternatives in Grails 2.0
问题描述
问题与旧版SO问题相同,但解决方案不再对于Grails 2.0有效 - 抽象域类不作为@MappedSuperclass处理,但始终保留在它自己的表中。如果我将它移到grails-app / domain之外,它根本不起作用。
那么有没有办法让抽象超类(或者更好的混合类)那么它的行为就像@MappedSuperclass(没有创建拥有共享id和公共字段的自己的表)?
我们遇到了同样的问题,用这种方法用grails 2.2.1(不是grails 2.0)解决了它:
在src / groovy下创建了抽象超类:
抽象类可审计{
日期dateCreated
Date lastUpdated
static constraints = {
dateCreated(display:false )
lastUpdated(显示:false)
}
}
在grails-app / domain下创建具体类'Parcel':
class Parcel extends Auditable {
...
}
您应该使用Grails 2.1或最新版本的Grails 2.2.3而不是2.0 .x来解决这种问题f映射。
The problem is the same as in the older SO question but the solution is no longer valid for Grails 2.0 - abstract domain class is not handled as @MappedSuperclass but is always persisted in it's own table. If I move it outside grails-app/domain it doesn't work at all.
So is there a way to have an abstract superclass (or even better a mixin) that would behave like @MappedSuperclass (without creating own table with shared id and common fields) ?
we had the same problem and solved it with grails 2.2.1 (not grails 2.0) this way:
created the abstract superclass under src/groovy:
abstract class Auditable {
Date dateCreated
Date lastUpdated
static constraints = {
dateCreated(display:false)
lastUpdated(display:false)
}
}
created the concrete class 'Parcel' under grails-app/domain:
class Parcel extends Auditable {
...
}
You should use Grails 2.1 or the latest release Grails 2.2.3 instead of 2.0.x to solve this kind of mapping.
这篇关于MappedSuperclass在Grails 2.0中的替代品的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!