Jpa 直接向DTO查询结果时出现语法错误

Jpa 直接向DTO查询结果时出现语法错误,jpa,spring-data-jpa,spring-data,dto,Jpa,Spring Data Jpa,Spring Data,Dto,我的母语查询- interface PodcastRepository: JpaRepository<Podcast, Long> { @Query(value = "SELECT new com.krtkush.sample.modules.podcast.models.PodcastDTO" + "(p.id, p.author, p.title, p.description c.name, c2.name) &quo

我的母语查询-

interface PodcastRepository: JpaRepository<Podcast, Long> {
    @Query(value = "SELECT new com.krtkush.sample.modules.podcast.models.PodcastDTO" +
            "(p.id, p.author, p.title, p.description c.name, c2.name) " +
            "AS sub_category_name FROM podcasts p " +
            "LEFT JOIN categories c ON p.podcast_category_id = c.category_id " +
            "LEFT JOIN categories c2 ON p.podcast_subcategory_id = c2.category_id " +
            "WHERE p.podcast_owner = :ownerId", nativeQuery = true)
    fun getPodcastsByOwner(@Param("ownerId")owner: Long): List<PodcastDTO>
}
接口PodcastRepository:JpaRepository{
@查询(value=“SELECT new com.krtkush.sample.modules.podcast.models.PodcastDTO”+
(p.id、p.author、p.title、p.description、c.name、c2.name)+
“作为播客p中的子类别名称”+
“在p.podcast\u category\u id=c.category\u id上左连接类别c”+
“在p.podcast_子类别_id=c2.category_id上左连接类别c2”+
“其中p.podcast_owner=:ownerId”,nativeQuery=true)
fun getPodcastsByOwner(@Param(“ownerId”)所有者:长):列表
}
但是,当我执行该函数时,我得到以下错误-

org.postgresql.util.PSQLException:错误:语法错误位于或接近“.”位置:15

位置15是
之后的
选择新com

我正在学习这个教程-
不同之处在于我使用的是SQL而不是JPQL。

您不能使用构造函数
新建com.krtkush.sample.modules.podcast.models.PodcastDTO
在nativeQuery中,您需要使用JPQL什么是等效的JPQL?当我尝试删除
nativeQuery=true
时,我得到
QuerySyntaxException:unexpected token:c靠近第1行第107列
您需要在JPQL中使用正确的实体和列名,或者使用接口来使用nativeQuery映射,但您需要使用查询中列的别名来匹配接口。在这里您可以找到有关第二条道路的详细信息