spring-projects / spring-projects/spring-data-rest
Cannot use @Valid on @Transient properties [DATAREST-1005]
@odrotbohm is already working on this.
Since Dec 31, 2020.
- Dominant language
- Java
- Stars
- 958
- Forks
- 568
- PR merge metrics
- No merged PRs in 30d
Description
Craig opened DATAREST-1005 and commented
An entity class like this:
public class Person {
@javax.persistence.Transient
@javax.validation.constraints.NotNull
private String temporary;
@javax.validation.constraints.NotNull
private String firstName;
}
Will result in an error when validated by Spring Data REST:
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.IllegalStateException: JSR-303 validated property 'person.temporary' does not have a corresponding accessor for Spring data binding - check your DataBinder's configuration (bean property versus direct field access)
at org.springframework.data.rest.core.ValidationErrors$1.getPropertyValue(ValidationErrors.java:90)
at org.springframework.validation.AbstractPropertyBindingResult.getActualFieldValue(AbstractPropertyBindingResult.java:99)
at org.springframework.validation.AbstractBindingResult.getRawFieldValue(AbstractBindingResult.java:283)
at org.springframework.validation.beanvalidation.SpringValidatorAdapter.getRejectedValue(SpringValidatorAdapter.java:260)
at org.springframework.validation.beanvalidation.SpringValidatorAdapter.processConstraintViolations(SpringValidatorAdapter.java:140)
at org.springframework.validation.beanvalidation.SpringValidatorAdapter.validate(SpringValidatorAdapter.java:94)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
The problem is that the getters/setters for the transient field aren't in the persistent entity metamodel (see DATACMNS-978) so they're not found when validation tries to use them at https://github.com/spring-projects/spring-data-rest/blob/2.6.0.RELEASE/spring-data-rest-core/src/main/java/org/springframework/data/rest/core/ValidationErrors.java#L89
Affects: 2.6 GA (Ingalls)
2 votes, 4 watchers
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.