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 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…