-
Notifications
You must be signed in to change notification settings - Fork 132
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
[Spring Boot v2.6.0-RC1] Entity callbacks invoked on both entity and projections #684
Comments
Do you see two invocations for the same row or is it just that you see a callback that happens on the projection when using projections? Generally, we try to read data as efficiently as possible so reading rows directly into a DTO projection, without creating the entity first doesn't impose any overhead. |
@mp911de thanks for the quick response. I don't see two invocations, but I do see the entity callback invoked when using projections of that entity. To be a bit more precise about the issue, let's assume we have a With all that set, if we get a projection using I hope this helped to clarify the scenario 🙂 |
That is expected as we want to read data directly into the projection. Right now, a lot of projections in Spring Data read data into a Generally one could argue that a projection isn't an entity and hence we should skip entity callbacks in that case alltogether. |
Got it, that makes sense! I can also see its benefits, but I wasn't sure which of the 2 was the expected behavior. The only downside is that it's hard to tell if the callback receives the complete entity or just a projection. We can always assume that all fields can be null, but that's still a bit unsafe (especially when we have nullability annotations). Any advice to handle this? As a side note, I usually inject other repositories in my custom callbacks, and I noticed that on v2.6.0-RC1, this caused a circular reference, which I think makes sense because callbacks now use |
Spring Boot 2.6 forbids by default circular bean arrangements. |
Hi,
I'm not sure if this is the right place to report this because the issue is on the Release Candidate of Spring Boot, so I'm not sure which version of
spring-data-r2dbc
we might need to check. Anyways, I hope this helps 🙂I'm using Spring Boot v2.6.0-RC1 to test issue #591, which was solved and shipped on this version. However, I noticed that custom entity callbacks are invoked for both the entity and any projection of that specific entity. I'm not sure if this is the expected behavior though, it could be convenient not having to repeat the same callbacks for many projections. But on the other hand, projections are usually intended to have fewer fields than the actual entity, so it can be easy to fall into NullPointerExceptions and errors of that sort.
Given this behavior is intended, what would be the best/safest way to tell if the entity received in the callback is some specific projection and not the entity?
As always, I'll be more than happy to help with a PR if needed. I'd only need some guidance in the best approach to take on this.
Cheers!
The text was updated successfully, but these errors were encountered: