Skip to content

ReactiveBeforeSaveCallback doesn't work with generic type #2822

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
danielimre opened this issue Apr 25, 2023 · 2 comments
Closed

ReactiveBeforeSaveCallback doesn't work with generic type #2822

danielimre opened this issue Apr 25, 2023 · 2 comments
Assignees
Labels
type: bug A general bug

Comments

@danielimre
Copy link

Before 3.0.5 the following was working for reactive before save callbacks:

public class MyBeforeSaveCallback<T> implements ReactiveBeforeSaveCallback<T> {
  @Override
  public Publisher<T> onBeforeSave(T entity, Document document, String collection) {...}
}

Then it could be defined as a bean like this:

@Bean
MyBeforeSaveCallback<Object> myCallback() {...}

This callback was found for arbitrary type.

In spring-data 3.0.5 this has stopped working. The callback is not found for any given type.

The change breaking this was most probably introduced with #2812

Workaround

The simplest workaround I found was just to eliminate the generic T and hardcode Object in MyBeforeSaveCallback like:

public class MyBeforeSaveCallback implements ReactiveBeforeSaveCallback<Object> {
  @Override
  public Publisher<Object> onBeforeSave(Object entity, Document document, String collection) {...}
}
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Apr 25, 2023
@futzlig
Copy link

futzlig commented Apr 28, 2023

Yes, I have the same problem with Spring Data JDBC and my BeforeConvertCallback:

    @Bean
    BeforeConvertCallback<DomainEntity> uuidGenerator() {
        return entity -> {
            if (entity.getId() == null) {
                entity.setId(UUID.randomUUID());
            }
            return entity;
        };
    }

It's not called anymore. The Workaround with an extra class resolves the problem. DomainEntity here is an interface.

odrotbohm added a commit that referenced this issue May 2, 2023
We now properly support generic entity callbacks defined via lambda declarations.

Fixes #2822.
@odrotbohm odrotbohm added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels May 2, 2023
@odrotbohm odrotbohm added this to the 3.0.6 (2022.0.6) milestone May 2, 2023
@odrotbohm
Copy link
Member

Sorry for the inconvenience. This should be fixed in the 3.0.6 and 3.1 snapshots. Feel free to give them a try!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
Development

No branches or pull requests

4 participants