问题
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) ?
回答1:
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.
来源:https://stackoverflow.com/questions/9717127/mappedsuperclass-alternatives-in-grails-2-0