Witam,
Próbuję zrobić klasową projekcje dla query repository. Powinna działać ponieważ wymaganie jest "the parameter names of its constructor must match properties of the root entity class." i się zgadzają. Ale z jakiegoś powodu wywala exception:
java.lang.ClassCastException: class ws.xx.posts.post.PostSnapshot cannot be cast to class ws.xx.posts.post.dto.query.PostDetailsQueryDTO (ws.xx.posts.post.PostSnapshot and ws.xx.posts.post.dto.query.PostDetailsQueryDTO are in unnamed module of loader 'app')
Pradopodobnie jest to jakieś drobne niedopatrzenie ale za nic nie mogę się zorientować gdzie.
Od razu chciałbym zaznaczyć że PostSnapshot jest w module 'posts-domain', PostDetailsQueryDTO jest w 'posts-app' a repozytorium jest w 'posts-adapters'.
Próbowałem również zrobić to bez użycia Lomboka ale rezultat jest ten sam.
Encja (Skonfigurowana jest zewnętrznie przez orm.xml to jest jej value object):
@EqualsAndHashCode
@ToString
@Getter(value = PACKAGE)
@NoArgsConstructor(access = PROTECTED)
@AllArgsConstructor(access = PACKAGE)
class PostSnapshot {
private long id;
private UUID postId;
private UUID ownerId;
private String title;
private String description;
private ZonedDateTime createDate;
}
DTO:
@Builder(toBuilder = true)
@EqualsAndHashCode
@ToString
@Getter
@AllArgsConstructor
public class PostDetailsQueryDTO implements Serializable {
private UUID postId;
private UUID ownerId;
private String title;
private String description;
private ZonedDateTime createDate;
}
QueryRepository:
interface PostQueryRepositoryImpl extends PostQueryRepository, Repository<PostSnapshot, Long> {
@Override
PostDetailsQueryDTO findByPostId(UUID postId);
@Override
Page<PostDetailsQueryDTO> findAll(Pageable pageable);
}