我试图在我的存储库中创建它:
public interface TaskRepository extends JpaRepository<Task, Long> {
@Query(value = "SELECT NEW example.NameAndDescription(task.name, task.description) FROM Task as task")
List<Task> findAll();
}
但我有一个错误:
引起:org.hibernate.hql.internal.ast.QuerySyntaxException:无法找到类[example.NameAndDescription] [SELECT NEW example.NameAndDescription(task.name,task.description)FROM server.entity.Task as task ]
我的课程:
public class NameAndDescription {
String name, description;
public NameAndDescription(String name, String description) {
this.name = name;
this.description = description;
}
public String getDescription() {
return description;
}
public String getName() {
return name;
}
public void setDescription(String description) {
this.description = description;
}
public void setName(String name) {
this.name = name;
}
}