spring-data-jpa
spring-data-jpa copied to clipboard
`JpaMetamodelMappingContext` should use `PersistentPropertyAccessorFactory` consistent with JPA
alienisty opened DATAJPA-1675 and commented
According to the documentation of Spring Data Commons chapter 3:
Note, that this section only applies to Spring Data modules that do not use the object mapping of the underlying data store (like JPA).
My reading is that everything that is described in that chapter should not apply to Spring Data JPA.
Now, JPA is happy to have final identifier fileds, but AbstractMappingContext installs either ClassGeneratingPropertyAccessorFactory or BeanWrapperPropertyAccessorFactory which both don't allow setting a final field while JPA does.
I think that either the documentation should be changed or a JPA compatible PersistentPropertyAccessorFactory should be used
Affects: 2.2.4 (Moore SR4)
Attachments:
- demo.zip (63.32 kB)
Jens Schauder commented
Could you elaborate where this causes problems? Currently I don't see where Spring Data JPA sets JPA entity values since the instantiation of entities is done by JPA
alienisty commented
Hello Jens, I ran into the problem when using PATCH method with Spring Data Rest and I narrowed it down to what AbstractMappingContext does, as explained in the description.
It seems the problem is when spring data is updating parts of an instance and bypasses JPA when setting values for final fields in that case. I thought I were very specific by giving the exact location causing the problem, but please let me know if you need further info and I will try to create a small test case
Jens Schauder commented
Sorry, I still don't follow.
Could you provide a reproducer demonstrating the issue? I.e. a minimal but complete project with a failing test that should succeed when the bug is fixed?
alienisty commented
Hello Jens Schauder,
Sorry it took a while, but attached you'll find a demonstration minimal project to reproduce the problem
@mp911de this might be a good one to work together on, since I'm not exactly sure what this would take.