I have an SQL statement with the names of the class instead of the names of the tables.
Then I use a ResultTransformer to map the result in a bean, but Hibernate does not transform the query(with the classes) in a query capable for Oracle.
The code is like this:
Session sx = hibernateTemplate.getSessionFactory().openSession();
SQLQuery q = sx.createSQLQuery(queryUser);
sottoInterventiPagatiList = (List<SottoInterventiPagatiBean>)q.setResultTransformer(Transformers.aliasToBean(SottoInterventiPagatiBean.class)).list();
the query is:
select pagaSott.codiSequPagaSottInte as codiSequPagaSottInte,
pagaSott.impoSostSottInte as impoSostSottInte,
pagaSott.impoRichSottInte as impoRichSottInte,
pagaSott.impoAcceSottInte as impoAcceSottInte,
pagaSott.impoAmmeSottInte as impoAmmeSottInte,
pagaSott.codiSottTipo as codiSottTipo,
pagaInte.tabAgriPsrClTipoInt.codiTipo as codiTipo,
ammiDomaAiut.descSottTipo as descSottTipo,
ammiDomaAiut.impoSpesTotaAmme as impoSpesTotaAmme,
ammiDomaAiut.impoTotaAmme as impoTotaAmme
from AmmissibilitaDomandaAiuto ammiDomaAiut,
PagamentiDoma pagaDoma,
PagaInte pagaInte, PagaSottInte pagaSott
where pagaDoma.codiDomaAiut = ammiDomaAiut.domandaByCodiDomaAiut.codiDoma
and pagaDoma.tabAgriPsrClMisure.codiMisu = ammiDomaAiut.misure.codiMisu
and pagaInte.tabAgriPsrPagamentiDoma.codiSequPagaDoma = pagaDoma.codiSequPagaDoma
and pagaInte.tabAgriPsrClTipoInt.codiTipo = ammiDomaAiut.tipiIntervento.codiTipo
and pagaSott.tabAgriPsrPagaInte.codiSequPagaInte = pagaInte.codiSequPagaInte
and pagaSott.codiSottTipo = ammiDomaAiut.sottoTipiIntervento.codiSottTipo
and ammiDomaAiut.domandaByCodiDomaAiut.codiDoma = 13
and ammiDomaAiut.misure.codiMisu = 6
the bean is:
public class SottoInterventiPagatiBean implements Serializable{
private static final long serialVersionUID = -1831093835824406823L;
private Integer codiSequPagaSottInte;
private Integer codiTipo;
private BigDecimal codiSottTipo;
private String descSottTipo;
private BigDecimal impoSostSottInte;
private BigDecimal impoRichSottInte;
private BigDecimal impoAcceSottInte;
private BigDecimal impoAmmeSottInte;
private BigDecimal impoSpesTotaAmme;
private BigDecimal impoTotaAmme;
public Integer getCodiSequPagaSottInte() {
return codiSequPagaSottInte;
}
public void setCodiSequPagaSottInte(Integer codiSequPagaSottInte) {
this.codiSequPagaSottInte = codiSequPagaSottInte;
}
public Integer getCodiTipo() {
return codiTipo;
}
public void setCodiTipo(Integer codiTipo) {
this.codiTipo = codiTipo;
}
public BigDecimal getCodiSottTipo() {
return codiSottTipo;
}
public void setCodiSottTipo(BigDecimal codiSottTipo) {
this.codiSottTipo = codiSottTipo;
}
public String getDescSottTipo() {
return descSottTipo;
}
public void setDescSottTipo(String descSottTipo) {
this.descSottTipo = descSottTipo;
}
public BigDecimal getImpoSostSottInte() {
return impoSostSottInte;
}
public void setImpoSostSottInte(BigDecimal impoSostSottInte) {
this.impoSostSottInte = impoSostSottInte;
}
public BigDecimal getImpoRichSottInte() {
return impoRichSottInte;
}
public void setImpoRichSottInte(BigDecimal impoRichSottInte) {
this.impoRichSottInte = impoRichSottInte;
}
public BigDecimal getImpoAcceSottInte() {
return impoAcceSottInte;
}
public void setImpoAcceSottInte(BigDecimal impoAcceSottInte) {
this.impoAcceSottInte = impoAcceSottInte;
}
public BigDecimal getImpoAmmeSottInte() {
return impoAmmeSottInte;
}
public void setImpoAmmeSottInte(BigDecimal impoAmmeSottInte) {
this.impoAmmeSottInte = impoAmmeSottInte;
}
public BigDecimal getImpoSpesTotaAmme() {
return impoSpesTotaAmme;
}
public void setImpoSpesTotaAmme(BigDecimal impoSpesTotaAmme) {
this.impoSpesTotaAmme = impoSpesTotaAmme;
}
public BigDecimal getImpoTotaAmme() {
return impoTotaAmme;
}
public void setImpoTotaAmme(BigDecimal impoTotaAmme) {
this.impoTotaAmme = impoTotaAmme;
}
}
Use session.createQuery(…) instead of createSQLQuery(…). createSQLQuery creates an SQL query, hibernate assumes that your query is already in sql format, then no other transformation is done.