如何在SPRING中制作构造函数表达式(标准)

时间:2016-07-04 19:03:39

标签: java spring hibernate spring-data spring-data-jpa

我试图在我的存储库中创建它:

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;
    }
}

0 个答案:

没有答案