5

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

Community
  • 1
  • 1
verglor
  • 616
  • 7
  • 21

1 Answers1

4

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.

Roman
  • 3,094
  • 1
  • 14
  • 11
  • This works as expected. thank you very much. Tested in Grails 2.4.5 – Dj Mamana Jul 15 '15 at 18:15
  • Worked for me with Grails 3.2.4 also, although I had to put all my associations in the base classes, even though they were the same for both. When I had them in the parent class, it couldn't find them (e.g., said no such property when I tried to access an association from an instance of the base class). Still, better than two entirely identical classes. Thanks! – Schmick Feb 14 '17 at 03:35