Conversation
|
|
||
| abstract Long countByTitleInAndTotalPagesGreaterThan(List<String> titles, int totalPages); | ||
|
|
||
| abstract Optional<BookDtoWithAuthorDto> queryByTitleContains(String title); |
There was a problem hiding this comment.
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.
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.
Are you sure this will work?
There was a problem hiding this comment.
Yes, there is a test that covers that case.
There was a problem hiding this comment.
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
|




@dstepanov I started looking at DTO association support as there are few reported issues. Seems like support for
ManyToOneis not added.