简体   繁体   中英

Sprint boot jpa, return custom class from query

I have some custom query ie:

@Query("SELECT cells.res, event.eventDate, count(*) FROM ABC abc " +
            "JOIN abc.data as cells " +
            "JOIN cells.samples as samples " +
            "JOIN samples.ev as event " +
            "WHERE event.id IN :ids "+
            "GROUP BY event.id, samples.id")

    Set<XYZProjection> findXYZBySubjectId(List<Long> ids);

( some data changed as I dont want ot paste real query;) )

and Ive created XYZProjection class, with 3 fields inside.

public class XYZProjection implements java.io.Serializable {
    private Long positive;
    private LocalDate eventDate;
    private Long count;
    public SubjectSamplesProjection(Long res, LocalDate date, Long count) {
        this.res = res;
        this.date = eventDate;
        this.count = count;
    }
    public Long getCount() {
        return count;
    }
    public LocalDate getDate() {
        return date;
    }
    public Long getRes() {
        return res;
    }
}

But then I get ConverterNotFoundException how can I fix that?

( Idea is to create a class, dont want trigger creating a table, and this class will return from this query )

thanks!

How findXYZBySubjectId() will work where there is no field called "subjectId" is available in POJO. And also your query is not clear.

please refer the link for more information:---

enter link description here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM