micronaut-data
micronaut-data copied to clipboard
DTO Projections: Property is not compatible with equivalent property on entity
Expected Behavior
Micronaut data 4.2.0 introduced nested DTO projections, so I've created the following:
public Review {
private UUID id;
private User user;
private Farm farm;
private String text;
private int stars;
private LocalDateTime createdAt;
private LocalDateTime updatedAt;
}
public ReviewDTO {
private UUID id;
private UserDTO user;
private String text;
private int stars;
private LocalDateTime updatedAt;
}
public User {
private UUID id;
private String username;
private String email;
//other fields
}
public UserDTO {
private UUID id;
private String username;
}
When I implement a method in a repository like so:
@R2dbcRepository(dialect = Dialect.POSTGRES)
public interface ReviewRepository extends ReactorPageableRepository<Review, UUID> {
@Join("user")
Mono<Page<ReviewDTO>> findByFarmIdOrderByUpdatedAtDesc(UUID farmId, Pageable pageable);
}
I expect it to fetch the User and map it to a DTO appropriately.
Actual Behaviour
I get the error titled above, stating that the property user in the entity Review cannot be mapped to UserDTO in ReviewDTO.
Steps To Reproduce
Run with the DTOs above
Environment Information
- Ubuntu 20.04
- JDK 17.0.6
- Micronaut 4.2.0
- Micronaut data 4.2.0
Example Application
https://github.com/boomermath/farmed
Version
4.2.0