Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MappedSuperclass Alternatives in Grails 2.0

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) ?

like image 601
verglor Avatar asked Oct 09 '22 09:10

verglor


1 Answers

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.

like image 159
Roman Avatar answered Oct 23 '22 03:10

Roman