Skip to content

GORM id and version added to abstract base-class not to domain class extending base-class #15364

@sbglasius

Description

@sbglasius

Expected Behavior

When using a common abstract base class for both entities and command objects (injecting Validateable), the generated
GORM code (id and version) are injected into the domain class.

Actual Behaviour

When using a common abstract base class for both entities and command objects (injecting Validateable), the generated GORM code (id and version) are injected into the abstract base class, and not into the entity object as expected.

This results in a validation error on a command object extending an abstract-base class that is also used to extend a domain class, on the fields id and version, even though they should not be part of the command object.

Example:

Base class:

abstract class BaseFoo  {
    String foo
}

Domain class:

class Foo extends BaseFoo {
    
    static constraints = {
        foo nullable: false
    }
}

Command class:
Domain class:

class FooCommand extends BaseFoo implements Validateable {
    
    static constraints = {
        foo nullable: false
    }
}

The decompiled BaseFoo.class contains id and version fields.

public abstract class BaseFoo implements GroovyObject {
    private String foo;
    Long id;
    Long version;
    
    // Getters and setters are generated into the base class as well.
}

Steps To Reproduce

Check out the example project and run

./gradlew clean test

And the only test will fail.

Environment Information

Ubuntu (irrelevant)

Example Application

https://github.com/sbglasius/grails-gorm-abstract-id-bug

Version

6.2.3 and 7.0.x

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions