grails-audit-logging-plugin icon indicating copy to clipboard operation
grails-audit-logging-plugin copied to clipboard

lastUpdatedBy is not getting updated

Open luke10 opened this issue 6 years ago • 6 comments

Version: org.grails.plugins:audit-logging:3.0.3

I am new to this plugin, but have noticed a fairly critical issue. The last_updated_by column is not being updated when entities are updated. However, it is being set when the entity is first created (along with created_by)

Could this be a bug in the new version?

I'm not sure what the expected behaviour is, but I would expect:

  • On insert, lastUpdatedBy should be left as NULL
  • On update, lastUpdatedBy should be updated to the current authenticated user

luke10 avatar Feb 24 '19 23:02 luke10

What's your plugin config?

robertoschwald avatar Feb 25 '19 06:02 robertoschwald

grails:
    plugin:
        auditLog:
            auditDomainClassName: 'my.package.AuditTrail'
            excluded: ['createdBy','dateCreated','lastUpdatedBy','lastUpdated','version']

luke10 avatar Feb 25 '19 11:02 luke10

Are you using the Stampable trait on the entities?

longwa avatar Feb 27 '19 21:02 longwa

I'm experiencing the same problem using version 3.0.1 (with Hibernate 5.1.16.Final) and the Stampable trait. I'm not trying to make lastUpdatedBy nullable like OP and initial value is set to match createdBy as expected. But changes to lastUpdatedBy afterwards are not saved to the database, whereas changes to other fields including lastUpdated are.

I can see that StampListener.handleUpdate is called after calling save(flush:true) and the value in the domain object is updated within the session of the one request. However, it's not saved to the database and subsequent requests show the unchanged value of lastUpdatedBy while all other changes to the domain including lastUpdated were persisted.

tekells-usgs avatar Mar 26 '19 16:03 tekells-usgs

A similar problem occurs if you independently implement the abstract class AbstractPersistenceEventListener. Within one thread, the changes applied in the implementation of the AbstractPersistenceEventListener class are available, and there are no changes in the other thread.

Example: https://github.com/MaxMoto1702/grails-AbstractPersistenceEventListener and grails-data-mapping/issues/1237

MaxMoto1702 avatar Apr 02 '19 14:04 MaxMoto1702

@tekells-usgs How did you finally deal with this problem? I had the same problem,thanks

zhangjiayu139 avatar Mar 07 '23 03:03 zhangjiayu139