8

Under Grails 2.4.4, we had classes we used as wrappers for domain objects.

They would look like this:

class Foo {
  @Delegate
  OurDomainClass ourDomainClass
  ...

}

This worked, but when trying to compile under Grails 3.0.11, we get this:

Foo.groovy: 14: Can't have an abstract method in a non-abstract class. The class 'Foo' must be declared abstract or the method 'org.springframework.validation.Errors org_grails_datastore_gorm_GormValidateable__errors$get()' must be implemented. @ line 14, column 1. class Foo { ^

Removing the @Delegate annotation will make compilation pass, but calls to methods of the underlying class obviously then do not work.

Is there a way to work around this or to achieve this same behavior and have it pass compilation under Grails 3?

Sean LeBlanc
  • 185
  • 11
  • I have the same problem. Have you find solution? – Samoth Jun 22 '16 at 14:48
  • have you tried adding `@Validatable` to your wrappers? – injecteer Jun 30 '16 at 09:13
  • In grails 3.x commands implements interface Validatable instead @Validatable... – Samoth Jun 30 '16 at 12:59
  • Excuse my ignorance but what is the idea behind wrapping the Domains with a class? Is it to decouple the DAO layer from the view layer so that this way the views have zero knowledge about the database structure? If so, does your service layer always return Wrapper objects? What about for your inserts and updates? Does your Service layer take in always Wrapper objects? – Viriato Apr 21 '17 at 22:10
  • @Viriato - This is so that the domain class itself is not cluttered with a bunch of methods - it's essentially being used as a Decorator. – Sean LeBlanc Aug 31 '17 at 21:47

2 Answers2

1

Does good old static hasMany = [] or static hasOne = [] won't do the job? Of course wrappers would be domain classes then too.

0

You can work around this by changing the wrapper class to implement the GORM traits:

class Foo implements GormValidateable, DirtyCheckable, Validateable {
    @Delegate
    OurDomainClass ourDomainClass
    ...
}

I went further and created my own interface:

class Foo implements GormDelegateHack {
    @Delegate
    OurDomainClass ourDomainClass
    ...
}

interface GormDelegateHack extends GormValidateable, DirtyCheckable, Validateable {
}

I filed issue #856 against grails-data-mapping, although it may be a Groovy bug.

timbonicus
  • 863
  • 2
  • 13
  • 27