Conversation
There was a problem hiding this comment.
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.ENTITYin 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. |
data-runtime/src/main/java/io/micronaut/data/runtime/query/internal/BasicStoredQuery.java
Show resolved
Hide resolved
...ocessor/src/main/java/io/micronaut/data/processor/visitors/RepositoryTypeElementVisitor.java
Outdated
Show resolved
Hide resolved
...del/src/main/java/io/micronaut/data/model/query/builder/sql/AbstractSqlLikeQueryBuilder.java
Show resolved
Hide resolved
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
|
...del/src/main/java/io/micronaut/data/model/query/builder/sql/AbstractSqlLikeQueryBuilder.java
Show resolved
Hide resolved
data-jdbc/src/test/groovy/io/micronaut/data/jdbc/h2/H2EmbeddedSpec.groovy
Show resolved
Hide resolved
data-runtime/src/main/java/io/micronaut/data/runtime/query/internal/BasicStoredQuery.java
Show resolved
Hide resolved
...del/src/main/java/io/micronaut/data/model/query/builder/sql/AbstractSqlLikeQueryBuilder.java
Show resolved
Hide resolved
| 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; | ||
| } |
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
@copilot open a new pull request to apply changes based on this feedback
|
@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>
|




Fix for issue #3668