-
Notifications
You must be signed in to change notification settings - Fork 198
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
DTO joins support issues #2761
base: 4.10.x
Are you sure you want to change the base?
DTO joins support issues #2761
Conversation
@@ -172,4 +173,6 @@ protected Book newBook(Author author, String title, int pages) { | |||
abstract List<Book> findByTitleInAndTotalPagesGreaterThan(List<String> titles, int totalPages); | |||
|
|||
abstract Long countByTitleInAndTotalPagesGreaterThan(List<String> titles, int totalPages); | |||
|
|||
abstract Optional<BookDtoWithAuthorDto> queryByTitleContains(String title); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having AuthorDto
as BookDto
field should work but compiler gives this error
error: Unable to implement Repository method: PostgresBookRepository.queryByTitleContains(String title). Property [author] of type [io.micronaut.data.tck.entities.AuthorDTO] is not compatible with equivalent property of type [io.micronaut.data.tck.entities.Author] declared in entity: io.micronaut.data.tck.entities.Book
So we might need to check nested types if compatible. I will commit potential fix for this, but still SELECT
does not use this joined entity and mapper also does not consider it when reading data.
if (!TypeUtils.areTypesCompatible(dtoPropertyType, pp.getType())) { | ||
throw new MatchFailedException("Property [" + propertyName + "] of type [" + dtoPropertyType.getName() + "] is not compatible with equivalent property of type [" + pp.getType().getName() + "] declared in entity: " + entity.getName()); | ||
boolean compatibleTypes = TypeUtils.areTypesCompatible(dtoPropertyType, pp.getType()); | ||
if (!compatibleTypes) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This might be the fix for initial issue. If field types are not simple field or same classes, then check if entity matches with DTO.
After this, new error is when reading data
io.micronaut.data.exceptions.DataAccessException: Error reading object for name [author] from result set: Column "author" not found [42122-224]
because mapper tries to read it into the field vs into joined object. Also, should method specify join type for the DTO or automatically assume join is requested?
@dstepanov I have committed changes in this PR that should fix DTO join issue. |
data-model/src/main/java/io/micronaut/data/model/runtime/RuntimePersistentEntity.java
Outdated
Show resolved
Hide resolved
// DTO might not have ID mapped, and in this case to maintain relation | ||
// we set random UUID as id to be able to read and make relation | ||
if (isDto) { | ||
return UUID.randomUUID(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you sure this will work?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, there is a test that covers that case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On the other hand, don't know if could break some user case, all tests we have are passing.
data-runtime/src/main/java/io/micronaut/data/runtime/operations/internal/sql/TypeUtils.java
Show resolved
Hide resolved
…aut-data into dto-support-issues
Quality Gate failedFailed conditions See analysis details on SonarCloud Catch issues before they fail your Quality Gate with our IDE extension SonarLint |
@dstepanov I started looking at DTO association support as there are few reported issues. Seems like support for
ManyToOne
is not added.