Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
509 views
in Technique[技术] by (71.8m points)

java - Unable to locate appropriate constructor

I'm trying to translate this query for my application

This is the native Query:

SELECT
TIPO_ELE
, COUNT(CASE WHEN TRATTAMENTO < 0 THEN 1 END) AS FATAL
, COUNT( CASE WHEN WARNING > 0 THEN 1 END) AS WARNING
, COUNT(case WHEN TRATTAMENTO > 0 THEN 1 END ) AS STATO_POSITIVO
, COUNT(*) AS TOTALE
FROM
V_ARCHIVIO_AUI
GROUP BY TIPO_ELE
ORDER BY TIPO_ELE ASC;

to use it with Hibernate

This is my code in DTO:

public List<AllineamentoSTSupport> allineamentoST(){
        List<AllineamentoSTSupport> resultList = ( List<AllineamentoSTSupport>) em.createQuery("SELECT NEW it.siemens.stams.dal.utils.AllineamentoSTSupport(v.id.tipoEle, " +
            "COUNT(CASE WHEN (v.trattamento < 0) THEN 1 END), " +
            "COUNT(CASE WHEN (v.warning > 0) THEN 1 END), " +
            "COUNT(CASE WHEN (v.trattamento > 0) THEN 1 END), " +
            "COUNT(*)) " +
            "FROM VArchivioAui v  GROUP BY v.id.tipoEle").getResultList();
        return resultList != null ? resultList : new ArrayList<>();
    }

and this is the class to cast query result:

public class AllineamentoSTSupport implements Serializable {
    private String tipoEle;
    private BigDecimal fatal;
    private BigDecimal statoPositivo;
    private Integer totale;
    private BigDecimal warning;

    public AllineamentoSTSupport() {}

    public AllineamentoSTSupport(String tipoEle, BigDecimal fatal, BigDecimal warning, BigDecimal statoPositivo, Integer totale) {
        this.tipoEle = tipoEle;
        this.fatal = fatal;
        this.statoPositivo = statoPositivo;
        this.totale = totale;
        this.warning = warning;
    }
}

also return this error

org.hibernate.hql.internal.ast.QuerySyntaxException: Unable to locate appropriate constructor on class [it.siemens.stams.dal.utils.AllineamentoSTSupport] [SELECT NEW it.siemens.stams.dal.utils.AllineamentoSTSupport(v.id.tipoEle, COUNT(CASE WHEN (v.trattamento < 0) THEN 1 END), COUNT(CASE WHEN (v.warning > 0) THEN 1 END), COUNT(CASE WHEN (v.trattamento > 0) THEN 1 END), COUNT(*)) FROM it.siemens.stams.dal.model.jpa.VArchivioAui v GROUP BY v.id.tipoEle]

Someone can help me?

question from:https://stackoverflow.com/questions/65889178/unable-to-locate-appropriate-constructor

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...