Assume I have those DTO:
public interface ForumDTO extends ForumBaseDTO{
Integer getId();
ThreadDTO getLastThread();
}
public interface ThreadDTO {
Integer getId();
Integer getCommentCount()
}
在我的代码库中,我使用这些数据传输对象作为投影来执行以下查询:
@Query("select forum.id as id, " +
"forum.name as name, " +
"lastThread.id as lastThread_id " +
"from Forum forum " +
"inner join forum.lastThread as lastThread " +
"where forum.parent.id = ?:"
)
Iterable<ForumDTO> findAllByParentId(Integer id);
使用这个仓库,我可以很好地访问ForumDTO中的id和name,但是对于lastThread,它只返回null。我尝试过as lastThread.Id
、as lastThread_id
、as lastThreadId
,但都没有起作用。