【JPA】query新对象 需要 构造函数

构造函数

    @Query("select g from Note g where id=?1" )
    Note findById(Long id);

    @Query("select new sample.jpa.domain.Note2(c.id,c.title,c.body,d.id) from Note c,Tag d where c.id=d.id")
    List<Note2> findTagid();
@Entity
public class Note2 {


    public Note2(Long id,String title,String body,Long tid){

        this.id=id;
        this.title = title;
        this.body = body;
        this.tid= tid;
    }

    @Id
    private Long id;

    private String title;

    private String body;

    public Long getTid() {
        return tid;
    }

    public void setTid(Long tid) {
        this.tid = tid;
    }

    private Long  tid;



    public String getBody() {
        return body;
    }

    public void setBody(String body) {
        this.body = body;
    }

    public long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }


}
原文地址:https://www.cnblogs.com/viewcozy/p/4743886.html