-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Problem with join
PostPosted: Tue Aug 16, 2011 8:22 am 
Newbie

Joined: Tue Aug 16, 2011 7:52 am
Posts: 3
Hello All,

I'm having a problem creating a query using criteria, take a look at my code:

Code:
DetachedCriteria criteria = DetachedCriteria.forClass(ScoListasSiafi.class,"LST");

criteria.createAlias("LST." + ScoListasSiafi.Fields.ITEM_AUTORIZACAO.toString(), "IAF", Criteria.INNER_JOIN);
criteria.createAlias("IAF." + ScoItemAutorizacaoForn.Fields.AUTORIZACAO_FORN.toString(), "AFN", Criteria.INNER_JOIN);
criteria.createAlias("IAF." + ScoItemAutorizacaoForn.Fields.FASES_SOLICITACAO.toString(), "FSC", Criteria.INNER_JOIN);
criteria.createAlias("AFN." + ScoAutorizacaoForn.Fields.PROPOSTA_FORNECEDOR.toString(),"PFN", Criteria.INNER_JOIN);
criteria.createAlias("PFN." + ScoPropostaFornecedor.Fields.LICITACAO.toString(),"LCT", Criteria.INNER_JOIN);

criteria.add(Restrictions.eq("LCT." + ScoLicitacao.Fields.NUMERO.toString(), numLicitacao));
criteria.add(Restrictions.eq("AFN." + ScoAutorizacaoForn.Fields.NRO_COMPLEMENTO.toString(), nroComplemento));
      
List<ScoListasSiafi> list = this.executeCriteria(criteria);


Each entity (such as ScoListasSiafi) has an Enum called Fields, where we have the name of the property at that entity), as the following code:
Code:
@Entity
@Table(name="sco_listas_siafi")
public class ScoListasSiafi implements Serializable {

[...]
   private ScoItemAutorizacaoForn scoItensAutorizacaoForn;
[...]
   //bi-directional many-to-one association to ScoItensAutorizacaoForn
   @ManyToOne
   @JoinColumns({
      @JoinColumn(name="iaf_afn_numero", referencedColumnName="afn_numero"),
      @JoinColumn(name="iaf_numero", referencedColumnName="numero")
      })
   public ScoItemAutorizacaoForn getScoItensAutorizacaoForn() {
      return this.scoItensAutorizacaoForn;
   }

   public void setScoItensAutorizacaoForn(ScoItemAutorizacaoForn scoItensAutorizacaoForn) {
      this.scoItensAutorizacaoForn = scoItensAutorizacaoForn;
   }

[...]
   public enum Fields{
      ITEM_AUTORIZACAO("scoItensAutorizacaoForn");

      private String fields;

      private Fields(String fields) {
         this.fields = fields;
      }

      @Override
      public String toString() {
         return this.fields;
      }
   }

}


The query that this criteria generates is the following:
Code:
select
        this_.ano_empenho as ano1_985_0_,
        this_.numero_lista as numero2_985_0_,
        this_.iaf_numero as iaf18_985_0_,
        this_.iaf_afn_numero as iaf19_985_0_,
        this_.data_ult_geracao as data3_985_0_,
        this_.especie as especie985_0_,
        this_.ind_af_assinada as ind5_985_0_,
        this_.ind_ativa as ind6_985_0_,
        this_.ind_situacao as ind7_985_0_,
        this_.ind_situacao_ant as ind8_985_0_,
        this_.numero_lista_siafi as numero9_985_0_,
        this_.qtde as qtde985_0_,
        this_.qtde_enviada as qtde11_985_0_,
        this_.seq_envio as seq12_985_0_,
        this_.seq_siafi as seq13_985_0_,
        this_.sequencia_assinada as sequencia14_985_0_,
        this_.valor as valor985_0_,
        this_.valor_enviado as valor16_985_0_,
        this_.version as version985_0_
    from
        AGH.sco_listas_siafi this_
    where
        lct5_.NUMERO=?
        and afn2_.NRO_COMPLEMENTO=?


Notice that the criteria had not generated any joins entries on that FROM clause and that is the error. (ERROR: missing FROM-clause entry for table "lct5_").

Does anyone knows what I'm doing wrong?

Cheers.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.