Skip to content

Fix embeddable projection retrieval#3774

Open
radovanradic wants to merge 10 commits into5.0.xfrom
radovanradic/issue-3668
Open

Fix embeddable projection retrieval#3774
radovanradic wants to merge 10 commits into5.0.xfrom
radovanradic/issue-3668

Conversation

@radovanradic
Copy link
Copy Markdown
Contributor

Fix for issue #3668

@radovanradic radovanradic marked this pull request as ready for review March 24, 2026 16:00
Copilot AI review requested due to automatic review settings March 24, 2026 16:00
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes issue #3668 by enabling repository methods to return embedded/embeddable projections (and nested embedded projections) by generating correct result metadata and SQL column projections/aliases so result mapping can hydrate the embeddable type instead of attempting scalar conversion.

Changes:

  • Treat embeddable query return types as DataType.ENTITY in the annotation processor so runtime mapping uses entity/embedded mapping.
  • Update SQL projection building to expand embedded projections into their constituent columns and alias columns to match embeddable property names (including nested embedded cases).
  • Add processor-, JDBC(H2)-, and Hibernate(JPA)-level tests covering embedded projection retrieval (including nullable and nested embedded projections) and an invalid projection type case.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated no comments.

Show a summary per file
File Description
data-tck/src/main/java/io/micronaut/data/tck/repositories/RestaurantRepository.java Adds repository methods that project embedded fields directly (required for reproducing/fixing #3668).
data-processor/src/test/groovy/io/micronaut/data/processor/sql/BuildQuerySpec.groovy Adds query-generation assertions and result datatype assertions for embedded and nested embedded projections, plus a negative test.
data-processor/src/main/java/io/micronaut/data/processor/visitors/RepositoryTypeElementVisitor.java Marks embeddable query results as DataType.ENTITY to drive correct runtime mapping.
data-model/src/main/java/io/micronaut/data/model/query/builder/sql/AbstractSqlLikeQueryBuilder.java Expands embedded projections into column lists and aliases columns to embeddable property names (supports nested embedded).
data-jdbc/src/test/java/io/micronaut/data/jdbc/h2/H2VehicleRepository.java Introduces a JDBC H2 repository used to validate nested embedded projection retrieval.
data-jdbc/src/test/groovy/io/micronaut/data/jdbc/h2/H2EmbeddedSpec.groovy Adds integration tests for embedded projection retrieval (non-null, nullable, and nested embedded).
data-hibernate-jpa/src/test/java/io/micronaut/data/hibernate/UserWithWhereRepository.java Adds an embeddable projection method in the Hibernate JPA test repo.
data-hibernate-jpa/src/test/groovy/io/micronaut/data/hibernate/AbstractHibernateQuerySpec.groovy Adds a Hibernate test asserting embedded audit projection retrieval works.

Copilot AI review requested due to automatic review settings March 25, 2026 10:44
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 10 out of 10 changed files in this pull request and generated 3 comments.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings March 25, 2026 11:00
@sonarqubecloud
Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
1 New Critical Issues (required ≤ 0)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 10 out of 10 changed files in this pull request and generated no new comments.

@radovanradic radovanradic requested a review from Copilot March 25, 2026 15:00
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 10 out of 10 changed files in this pull request and generated 4 comments.

Comment on lines +684 to +690
DataType resultDataType = TypeUtils.resolveDataType(type, dataTypes);
if (operationType == DataMethod.OperationType.QUERY
&& (type.hasStereotype(Embeddable.class)
|| type.hasStereotype("jakarta.persistence.Embeddable")
|| type.hasStereotype("javax.persistence.Embeddable"))) {
resultDataType = DataType.ENTITY;
}
Copy link

Copilot AI Mar 25, 2026

Choose a reason for hiding this comment

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

Processor-side embeddable handling is slightly broader than the runtime-side logic (which additionally checks resolvedResultDataType == DataType.OBJECT). Aligning these conditions would reduce divergence between compile-time metadata and runtime inference, making future fixes less error-prone (e.g., only override to ENTITY when the resolved type would otherwise be OBJECT).

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@copilot open a new pull request to apply changes based on this feedback

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 25, 2026

@radovanradic I've opened a new pull request, #3780, to work on those changes. Once the pull request is ready, I'll request review from you.

#3780)

* Initial plan

* Align processor-side embeddable DataType resolution with runtime-side logic

Co-authored-by: radovanradic <10271067+radovanradic@users.noreply.github.com>
Agent-Logs-Url: https://github.com/micronaut-projects/micronaut-data/sessions/ccd7e35c-c41e-4c35-a851-04ac7c384bb2

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: radovanradic <10271067+radovanradic@users.noreply.github.com>
@sonarqubecloud
Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
1 New Critical Issues (required ≤ 0)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants