I'm using validation annotations on an entity class with a set of children. I've included @Min on the @Id field of both the parent and child entity classes, along with a validation group to limit validation of the Id to update operations only. @Valid annotation is specified for the set of children to ensure that the object graph is processed by the validator.
This works well except for the scenario where a new child is added to the set for an existing parent and the parent is validated for update: the child's Id has not yet been generated and hence a constraint violation is raised for the @Min validation.
Can anyone please advise how to handle this scenario? I'm beginning to wonder if it is usual to validate an @Id field? I've seen examples both with and without such validation.
[edit] I should clarify, this is manual validation using LocalValidatorFactoryBean. No problem with this scenario when Hibernate validates pre- the update. I assume Hibernate has dealt with generating the new Id for the new child by this point. [/edit]
Many thanks
|