I found two solutions:
1. Using a class to convert:
@Query("SELECT new com.example.project.TestPojo(tt, at.field, at.anotherField) from TableTest tt LEFT JOIN AnotherTable at ON at.commonField = tt.commonField") List<TestPojo> findAllPojo(List<TableTestDTO> TableTestDTOList);
Class:
package com.example.project; @Getter @Setter @NoArgsConstructor @AllArgsConstructor public class TestPojo { private Long tt; private String field; private String anotherField; }
2. Using an interface to convert:
@Query("SELECT tt AS tt, at.field AS field, at.anotherField AS anotherField from TableTest tt LEFT JOIN AnotherTable at ON at.commonField = tt.commonField") List<TestPojo> findAllPojo(List<TableTestDTO> TableTestDTOList);
Interface:
public interface TestPojo { Long getTt(); String getField(); String getAnotherField(); }