Skip to content

HandleBeforeLinkSave method returns old linked entity [DATAREST-1241] #1600

Closed

Description

@spring-projects-issues

Abhinav Sonkar opened DATAREST-1241 and commented

The method annotated with @HandleBeforeLinkSave takes 2 arguments - entity which is updated and the linked object being modified.

@HandleBeforeLinkSave
public void handleBeforeLinkSave(Object source, Object linked) {
   ...
}

In case of a PATCH or POST call, the linked object is a PersistentSet with both old and new values as these are augmenting HTTP methods.

But in case of a PUT call, the linked object is a PersistentSet with only old value. The new value passed in the request is not accessible. This makes it impossible to perform validations and/or business logic based on the new value of linked object.

Currently I am not aware of any workarounds to this issue.

After inspecting the Spring Data Rest  code I think the following line in RepositoryPropertyReferenceController.java:

publisher.publishEvent(new BeforeLinkSaveEvent(prop.accessor.getBean(), prop.propertyValue));

 must be changed to:

publisher.publishEvent(new BeforeLinkSaveEvent(prop.accessor.getBean(), prop.accessor.getProperty(prop.property)));

The same issue would affect the AfterLinkSaveEvent so below line:

publisher.publishEvent(new AfterLinkSaveEvent(result, prop.propertyValue));

should also be changed to:

publisher.publishEvent(new AfterLinkSaveEvent(result, prop.accessor.getProperty(prop.property)));

 

 


Affects: 2.6.11 (Ingalls SR11)

Referenced from: commits 79cbc1e, 23b66fa

5 votes, 6 watchers

Activity

  1. spring-projects-issues commented on Sep 20, 2018

    @spring-projects-issues
    Author

    mathomas commented

    I'm being bitten by the same issue, which makes it impossible for me to handle the created application event and send a websocket message with all the needed info.  I had independently thought of the same solution presented in the main ticket, and it also applies to link delete events

  2. spring-projects-issues commented on Jun 20, 2019

    @spring-projects-issues
    Author

    Doogiemuc commented

    +1   I stumbled over the same problem.   Looks like the code has changed in current version of spring. Now it looks like that @HandleBeforeLinkSave annotated method receives the NEW value as second parameter.  And only the new value when POSTing

  3. amnonkhen commented on Dec 8, 2021

    @amnonkhen

    Is there any update on this? We are affected as well?

  4. added 2 commits that reference this issue on Jun 17, 2026
    d7e60af
    64a4de2
  5. added this to the 5.0.7 (2025.1.7) milestone on Jun 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

type: bug

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions