MappedSuperclass Alternatives in Grails 2.0

我只是一个虾纸丫 提交于 2019-12-14 00:59:29

问题


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

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