spring-data-jpa
spring-data-jpa copied to clipboard
Auditing Users does not work [DATAJPA-1697]
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:
- demo.zip (126.58 kB)
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?
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