Skip to content

Consider embedded properties in the QBE queries #2100

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

mipo256
Copy link
Contributor

@mipo256 mipo256 commented Jul 26, 2025

Closes #2099
Closes #1986

This PR enhances the RelationalExampleMapper by making it consider embedded properties and specifiers for them.

As it turned out during resolution of #1986, the embedded properties were kind of ignored in QBE.

Current algorithm works more a less the same way, it just traverses the Example recursively from direct properties defined in the root probe, all the way down to the deeply embedded leafs.

Tests are included in the PR.

CC: @mp911de @schauder

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jul 26, 2025
@mp911de mp911de added type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged labels Aug 4, 2025
@mipo256
Copy link
Contributor Author

mipo256 commented Aug 5, 2025

Signed-off the commits

@mipo256 mipo256 force-pushed the GH-2099 branch 2 times, most recently from 7045c5c to 3d8fa6e Compare August 5, 2025 20:40
…rties in QBE

Signed-off-by: mipo256 <mikhailpolivakha@gmail.com>
Copy link
Member

@mp911de mp911de left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR goes into the right direction. There's quite some noise and parameter and variable names are quite lengthy. Long names add complexity and from my perspective, they do not improve readability or understandability by explaining different domains.


Object actualPropertyValue = entityPropertiesAccessor.getProperty(property);

if (property.isEmbedded() && actualPropertyValue != null) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally, we don't distinguish based on whether the property is an embedded one but rather whether it is an entity. At some point it should be possible to express criteria based across objects that are part of the aggregate (like it is done in JPA, we consider embeddables and references).

return Query.query(criteria);
}

private <T> @NotNull List<Criteria> buildCriteriaRecursive( //
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Care to remove all those lingering @NotNull annotations?

* @return query
*/
private <T> Query getMappedExample(Example<T> example, RelationalPersistentEntity<?> entity) {
private <T> Query getMappedExample(Example<T> example, RelationalPersistentEntity<?> persistentEntity) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the reason behind the renaming?

@@ -22,23 +22,31 @@
import java.util.List;
import java.util.Optional;

import org.jetbrains.annotations.NotNull;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't want to have Jetbrains annotations here.

) {
final List<Criteria> criteriaBasedOnProperties = new ArrayList<>();

persistentEntity.doWithProperties((PropertyHandler<RelationalPersistentProperty>) property -> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Use a for-loop instead of callback-style to reduce stack frames.

* @param criteriaBasedOnProperties collection of {@link Criteria} objects to potentially enrich.
* @param currentPropertyPath the dot-separated path of the passed {@code property}.
*/
private void processEmbeddedRecursively(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like a duplication of the general code that collects criteria for example matching. Should be consolidated.

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

Successfully merging this pull request may close these issues.

Embedded objects are mostly ignored in QBE queries JDBC: QBE withIgnoreNullValues does not ignore nulls in embedded classes of the Example
4 participants