Grails adding version to command object causes id and version from params not to be bound

StackOverflow https://stackoverflow.com/questions/17766392

  •  03-06-2022
  •  | 
  •  

Вопрос

I apologize if I'm missing something really obvious here but I've been pulling my hair out with this issue.

I have a command object:

class MyCommand {
    Long id
    String value
}

I bind to this in my controller:

public update(MyCommand myCmd) {


}

Everything is fine in this scenario. Now I'm trying to add the version field, which is passed in the request parameters to the command object:

class MyCommand {
    Long id
    Long version
    String value
}

Now however when the binding happens the id and version are always null, even though they are present in the params object.

I suspected that there may be some special handling for id / version attributes related to how grails handles optimistic locking (as this is ultimately why I'm doing this) but the issue is present at the command object independent of any domain object.

I'm baffled why this is not working. Is there some special case when version is present on a command object?

Это было полезно?

Решение

Seems this is by design per Jeff Brown jira

The data binding explicitly avoids binding id or version [if] they both exist and does this by design. This is a shield against potential security problems relevant to data binding as it relates to domain classes. A simple work around for command objects would be to name the properties with something like "idValue" and "versionValue" or anything other than "id" and "version".

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top