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

Auditing Users does not work [DATAJPA-1697]

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

anpieber opened DATAJPA-1697 and commented

Dear Spring-Development-Team,

Auditing for users is not working for quite a while now (since the upgrade from 2.0.4.RELEASE to 2.1.4.RELEASE). I know that it worked before the upgrade. It just took me lots of time finding out, that it does no longer work...

The core problem is that the AuditingEntityListener is expecting the object to be modified in place, but the AuditingHandler returns a new object. Therefore the changes never make the way into the DB. In fact I debugged the problem and it's located somewhere in the AuditableBeanWrapper class. If you monitor the target object in the wrapper (AuditableBeanWrapper) it stays bascially the same until this line. auditor.filter(__ -> isNew).ifPresent(foo -> wrapper.setCreatedBy(foo)); (AuditingHandler:198). Debugging the path further down you see that the object inside wrapper is modified in PersistentPropertyAccessor:78 in the accessor.setProperty(leafProperty, value); method call. I tried to debug into this call but intellij does not return any more information on this one.

Please feel free to contact me for any further information. Any idea would be really helpful!

Thank you very much and kind regards, Andreas


Affects: 2.2.5 (Moore SR5)

Attachments:

spring-projects-issues avatar Mar 17 '20 13:03 spring-projects-issues

Jens Schauder commented

Could you please provide a reproducer? I.e. a small but complete project demonstrating the issue preferable in the form of a failing test?

spring-projects-issues avatar Mar 17 '20 14:03 spring-projects-issues

anpieber commented

OK, I've found out the reason for the problem and attached a working and a failing test. The problem is the kotlin "val" keyword. Especially this creates all the behavior I've written in the description of the ticket. Especially this problem that a modification of the entity itself is required by spring boot and the return value is ignored. I've no problem that val is not supported, but it's supported for ID and version and I would basically expect that at least an exception is thrown or something else... At least a mentioning in the documentation would be nice.

Thank you very much and kind regards, Andreas Pieber

spring-projects-issues avatar Mar 18 '20 12:03 spring-projects-issues

Jens Schauder commented

Ok, that makes sense

spring-projects-issues avatar Mar 18 '20 12:03 spring-projects-issues