【发布时间】:2020-09-25 16:21:02
【问题描述】:
我正在尝试使用存储库直接从数据库中从实体投射 DTO。
@Query(value = "SELECT NEW com.jm.online_store.model.dto.ProductDto(p.id, p.comments) FROM
Product p WHERE p.id = :id")
ProductDto getCommentProductDto(@Param("id") Long productId);
但是我不断收到错误
java.sql.SQLSyntaxErrorException:您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以了解在 '.作为 col_1_0_ 来自产品 product0_ 内部加入评论 cmets1_ 在 product0_ 上。在第 1 行
在我尝试将 Collection 作为查询构造函数参数传递之前,一切都可以正常工作。
我的 DTO 课程
public class ProductDto {
private java.lang.Long id;
private Collection<Comment> comments;
public ProductDto(java.lang.Long id, Collection<Comment> comments) {
this.id = id;
this.comments = comments;
}
public ProductDto(java.lang.Long id) {
this.id = id;
}
public ProductDto() {
}
public java.lang.Long getId() {
return id;
}
public void setId(java.lang.Long id) {
this.id = id;
}
public Collection<Comment> getComments() {
return comments;
}
public void setComments(Collection<Comment> comments) {
this.comments = comments;
}
}
任何建议都将受到高度赞赏,现在已经坚持了几天......
【问题讨论】: