我有一个SQL语句,其中包含类的名称,而不是表的名称。然后,我使用ResultTransformer将结果映射到bean中,但是Hibernate不会在支持Oracle的查询中转换查询(带有类)。代码如下:
Session sx = hibernateTemplate.getSessionFactory().openSession();
SQLQuery q = sx.createSQLQuery(queryUser);
sottoInterventiPagatiList = (List<SottoInterventiPagatiBean>)q.setResultTransformer(Transformers.aliasToBean(SottoInterventiPagatiBean.class)).list();查询为:
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 = 6bean是:
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;
} }
发布于 2011-10-25 16:36:16
使用session.createQuery(...)而不是createSQLQuery(...)。createSQLQuery创建一个SQL查询,hibernate假设您的查询已经是sql格式,然后不进行其他转换。
https://stackoverflow.com/questions/7886477
复制相似问题