首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Hibernate SQL转换

Hibernate SQL转换
EN

Stack Overflow用户
提问于 2011-10-25 16:17:37
回答 1查看 506关注 0票数 0

我有一个SQL语句,其中包含类的名称,而不是表的名称。然后,我使用ResultTransformer将结果映射到bean中,但是Hibernate不会在支持Oracle的查询中转换查询(带有类)。代码如下:

代码语言:javascript
复制
 Session sx = hibernateTemplate.getSessionFactory().openSession();
   SQLQuery q = sx.createSQLQuery(queryUser);
   sottoInterventiPagatiList = (List<SottoInterventiPagatiBean>)q.setResultTransformer(Transformers.aliasToBean(SottoInterventiPagatiBean.class)).list();

查询为:

代码语言:javascript
复制
 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

bean是:

代码语言:javascript
复制
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;
  }  

}

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-10-25 16:36:16

使用session.createQuery(...)而不是createSQLQuery(...)。createSQLQuery创建一个SQL查询,hibernate假设您的查询已经是sql格式,然后不进行其他转换。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7886477

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档