Skip to content

Conversation

@darioseidl
Copy link
Contributor

@darioseidl darioseidl commented May 26, 2019

This is a fix for https://jira.spring.io/browse/DATAREST-1213. In some version after org.springframework.data:spring-data-rest-webmvc:2.4.4.RELEASE, HTTP PATCH and PUT requests with a projection would fail (using PATCH/PUT with projections makes sense when using return-body-on-update/return-body-on-create).

When using a projection, the payload in the PersistentEntityResource in RepositoryEntityController ends up as a dynamic JDK proxy and ETag.getVersionInformation fails with

java.lang.IllegalArgumentException: Target bean of type org.springframework.data.rest.webmvc.$Proxy129 is not of type of the persistent entity (org.springframework.data.rest.webmvc.jpa.Category)!: org.springframework.data.rest.webmvc.$Proxy129	at org.springframework.util.Assert.instanceCheckFailed(Assert.java:655)	at org.springframework.util.Assert.isInstanceOf(Assert.java:574)	at org.springframework.data.mapping.model.BasicPersistentEntity.verifyBeanType(BasicPersistentEntity.java:551)	at org.springframework.data.mapping.model.BasicPersistentEntity.getPropertyAccessor(BasicPersistentEntity.java:453)	at org.springframework.data.rest.webmvc.support.ETag.getVersionInformation(ETag.java:169)	at org.springframework.data.rest.webmvc.support.ETag.from(ETag.java:87)	at org.springframework.data.rest.webmvc.support.ETag.verify(ETag.java:105)	at org.springframework.data.rest.webmvc.RepositoryEntityController.patchItemResource(RepositoryEntityController.java:412) 

I'm not quite sure what's the canonical way to unproxy a JDK proxy in Spring Data, the proxy implement TargetAware so that seems to be an easy solution.

I would be very happy if this could be reviewed and merged. This bug affects us in two projects and currently prevents us from upgrading to any recent version of Spring Boot / Spring Data in one of them.

  • You have read the Spring Data contribution guidelines.
  • There is a ticket in the bug tracker for the project in our JIRA.
  • You use the code formatters provided here and have them applied to your changes. Don’t submit any formatting related changes.
  • You submit test cases (unit or integration tests) that back your changes.
  • You added yourself as author in the headers of the classes you touched. Amend the date range in the Apache license header if needed. For new types, add the license header (copy from another file and set the current year only).
odrotbohm pushed a commit that referenced this pull request Oct 26, 2020
odrotbohm added a commit that referenced this pull request Oct 26, 2020
Simplified tests and domain code. Reinstantiated accidentally removed method in PersistentEntityResource. Original pull request: #355.
odrotbohm pushed a commit that referenced this pull request Oct 26, 2020
odrotbohm added a commit that referenced this pull request Oct 26, 2020
Simplified tests and domain code. Reinstantiated accidentally removed method in PersistentEntityResource. Original pull request: #355.
odrotbohm pushed a commit that referenced this pull request Oct 26, 2020
odrotbohm added a commit that referenced this pull request Oct 26, 2020
Simplified tests and domain code. Reinstantiated accidentally removed method in PersistentEntityResource. Original pull request: #355.
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jan 4, 2021
@gregturn gregturn changed the base branch from master to main April 16, 2021 17:55
@odrotbohm
Copy link
Member

That's already been merged with 26410a0.

@odrotbohm odrotbohm closed this Jul 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status: waiting-for-triage An issue we've not yet triaged

3 participants