spring-data-jpa icon indicating copy to clipboard operation
spring-data-jpa copied to clipboard

`JpaMetamodelMappingContext` should use `PersistentPropertyAccessorFactory` consistent with JPA

Open spring-projects-issues opened this issue 5 years ago • 5 comments
trafficstars

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:

spring-projects-issues avatar Feb 06 '20 09:02 spring-projects-issues

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

spring-projects-issues avatar Feb 10 '20 13:02 spring-projects-issues

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

spring-projects-issues avatar Feb 27 '20 06:02 spring-projects-issues

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?

spring-projects-issues avatar Feb 27 '20 07:02 spring-projects-issues

alienisty commented

Hello Jens Schauder,

Sorry it took a while, but attached you'll find a demonstration minimal project to reproduce the problem

spring-projects-issues avatar Jul 21 '20 07:07 spring-projects-issues

@mp911de this might be a good one to work together on, since I'm not exactly sure what this would take.

gregturn avatar Jul 31 '23 21:07 gregturn