spring-projects / spring-projects/spring-data-rest

Cannot use @Valid on @Transient properties [DATAREST-1005]

Open
#1,368 6 comments 2 reactions 1 assignee View on GitHub

@odrotbohm is already working on this.

Since Dec 31, 2020.

type: bug
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.