-->
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.  [ 8 posts ] 
Author Message
 Post subject: fetch still hit the database with queries
PostPosted: Fri Sep 03, 2004 8:28 pm 
Beginner
Beginner

Joined: Fri Apr 16, 2004 10:25 am
Posts: 44
Location: Brazil
I'm trying to fetch to table so hibernate dont keeping hitting the DB but it seems that the fetch doesnt work

Hibernate version: 2.1.6

Mapping documents:
Code:
    <class name="com.br.resource.csu.lembranca.dao.hibernate.persisted.Documento" table="SSC_documento">
        <composite-id name="docPK" class="com.br.resource.csu.lembranca.dao.hibernate.persisted.DocumentoPK">
         <key-many-to-one name="codCli" column="COD_CLI"/>
          <key-property name="inxDoc" column="INX_DOC"/>
        </composite-id>
      <set name="regras" inverse="true" lazy="true" cascade="all">
          <key>
             <column name="inx_doc"/>
             <column name="cod_cli"/>
          </key>
          <one-to-many class="com.br.resource.csu.lembranca.dao.hibernate.persisted.DocumentoRegra"/>
      </set>
        <property name="codInstalacao"  column="COD_INSTALACAO"/>
        <property name="codLivroLeitura"        column="COD_LIVRO_LEITURA"/>
        <property name="codLocalidade"  column="COD_LOCALIDADE"/>
        <property name="codLoteFaturamento"     column="COD_LOTE_FATURAMENTO"/>
        <property name="codMotivoExc"   column="COD_MOTIVO_EXC"/>
        <property name="codTipoDoc"     column="COD_TIPO_DOC"/>
        <property name="codUnidOper"    column="COD_UNID_OPER"/>
        <property name="datCriacaoFatura"       column="DAT_CRIACAO_FATURA"/>
        <property name="datEmissaoFatura"       column="DAT_EMISSAO_FATURA"/>
        <property name="datExc" column="DAT_EXC"/>
        <property name="datFimCob"      column="DAT_FIM_COB"/>
        <property name="datInclusaoReg" column="DAT_INCLUSAO_REG"/>
        <property name="datIniCob"      column="DAT_INI_COB"/>
        <property name="datPrevCorte"   column="DAT_PREV_CORTE"/>
        <property name="datProcArqOrg"  column="DAT_PROC_ARQ_ORG"/>
        <property name="datVenctoFatura"        column="DAT_VENCTO_FATURA"/>
        <property name="flgDebAut"      column="FLG_DEB_AUT"/>
        <property name="indContencioso" column="IND_CONTENCIOSO"/>
        <property name="mesRefFatura"   column="MES_REF_FATURA"/>
        <property name="numFatura"      column="NUM_FATURA"/>
        <property name="qtdTentativa"   column="QTD_TENTATIVA"/>
        <property name="totFaturaAvisoDeb"      column="TOT_FATURA_AVISO_DEB"/>
        <property name="vlrFatura"      column="VLR_FATURA"/>
    </class>

    <class name="com.br.resource.csu.lembranca.dao.hibernate.persisted.Cliente" table="SSC_CLIENTE">
      <id name="codCli" column="COD_CLI" type="integer">
         <generator class="increment"/>
      </id>
      <bag name="documentos" table="SSC_documento" inverse="true" lazy="true" cascade="all">
          <key column="COD_CLI"/>
          <one-to-many class="com.br.resource.csu.lembranca.dao.hibernate.persisted.Documento"/>
      </bag>
      <bag name="enderecos" table="SSC_endereco_cli" inverse="true" lazy="true" cascade="all">
          <key column="COD_CLI"/>
          <one-to-many class="com.br.resource.csu.lembranca.dao.hibernate.persisted.EnderecoCliente"/>
      </bag>
      <bag name="telefones" table="SSC_fone_cli" inverse="true" lazy="true" cascade="all">
          <key column="COD_CLI"/>
          <one-to-many class="com.br.resource.csu.lembranca.dao.hibernate.persisted.TelefoneCliente"/>
      </bag>
      <bag name="doctoPessoa" table="SSC_REL_CLI_DOCTO" inverse="true" lazy="true" cascade="all">
          <key column="COD_CLI"/>
          <one-to-many class="com.br.resource.csu.lembranca.dao.hibernate.persisted.DocumentoCliente"/>
      </bag>

      <bag name="campanhas" table="SSC_REL_CLIENTE_CAMPANHA" inverse="true" lazy="true" cascade="all">
          <key column="COD_CLI"/>
          <one-to-many class="com.br.resource.csu.lembranca.dao.hibernate.persisted.ClienteCampanha"/>
      </bag>
        <property name="codClasse"       column="COD_CLASSE"/>
        <property name="codCliExt"       column="COD_CLI_EXT"/>
        <many-to-one name="codOrg"      column="COD_ORG"/>
        <property name="datInclusao"    column="DAT_INCLUSAO"/>
        <property name="dscEmail"       column="DSC_EMAIL"/>
        <property name="indSituaFornec" column="IND_SITUA_FORNEC"/>
        <property name="nomCli"       column="NOM_CLI"/>
        <property name="vlrSldDev"       column="VLR_SLD_DEV"/>
    </class>


Code between sessionFactory.openSession() and session.close():
Code:
   public Collection findRetornoLight () throws DaoException {
      Collection colDoc = null;
      try {
          colDoc = session.find("select doc from Documento doc inner join fetch doc.docPK.codCli cliente ");// +
//                " where doc.datExc is null AND "+
//                 "doc.docPK.codCli in "+
//                 "(select cliCampanha.codCli from ClienteCampanha cliCampanha where cliCampanha.codCampanha = 1) AND "+
//                 "doc.docPK.codCli in "+
//                 "(select end.codCli from EnderecoCliente end where end.flgRetornoLight = 'S') OR "+
//                 "doc.docPK.codCli in "+
//                 "(select fone.codCli from TelefoneCliente fone where fone.flgRetornoLight = 'S') OR "+
//                 "doc.docPK.inxDoc in "+
//                 "(select docReg.doc.docPK.inxDoc from DocumentoRegra docReg where "+
//                 "docReg.flgRetornoLight = 'S' and docReg.indStatusRegra = 3 and "+
//                 "docReg.inxRegraCampanha.codCampanha = 1) and rownum < 100");

      } catch (HibernateException e) {
         e.printStackTrace();
         throw new DaoException(e.getMessage());
      }
      return colDoc;
   }


Name and version of the database you are using: oracle 8i



LOG :

Code:
21:32:57,119 INFO  [STDOUT] Hibernate: select cliente0_.COD_CLI as COD_CLI0_, cliente0_.COD_CLASSE as COD_CLASSE0_, cliente0_.COD_CLI_EXT as COD_CLI_3_0_, cliente0_.COD_ORG as COD_ORG0_, cliente0_.DAT_INCLUSAO as DAT_INCL5_0_, cliente0_.DSC_EMAIL as DSC_EMAIL0_, cliente0_.IND_SITUA_FORNEC as IND_SITU7_0_, cliente0_.NOM_CLI as NOM_CLI0_, cliente0_.VLR_SLD_DEV as VLR_SLD_9_0_ from SSC_CLIENTE cliente0_ where cliente0_.COD_CLI=?
21:32:57,127 INFO  [STDOUT] Hibernate: select cliente0_.COD_CLI as COD_CLI0_, cliente0_.COD_CLASSE as COD_CLASSE0_, cliente0_.COD_CLI_EXT as COD_CLI_3_0_, cliente0_.COD_ORG as COD_ORG0_, cliente0_.DAT_INCLUSAO as DAT_INCL5_0_, cliente0_.DSC_EMAIL as DSC_EMAIL0_, cliente0_.IND_SITUA_FORNEC as IND_SITU7_0_, cliente0_.NOM_CLI as NOM_CLI0_, cliente0_.VLR_SLD_DEV as VLR_SLD_9_0_ from SSC_CLIENTE cliente0_ where cliente0_.COD_CLI=?
21:32:57,135 INFO  [STDOUT] Hibernate: select cliente0_.COD_CLI as COD_CLI0_, cliente0_.COD_CLASSE as COD_CLASSE0_, cliente0_.COD_CLI_EXT as COD_CLI_3_0_, cliente0_.COD_ORG as COD_ORG0_, cliente0_.DAT_INCLUSAO as DAT_INCL5_0_, cliente0_.DSC_EMAIL as DSC_EMAIL0_, cliente0_.IND_SITUA_FORNEC as IND_SITU7_0_, cliente0_.NOM_CLI as NOM_CLI0_, cliente0_.VLR_SLD_DEV as VLR_SLD_9_0_ from SSC_CLIENTE cliente0_ where cliente0_.COD_CLI=?
21:32:57,143 INFO  [STDOUT] Hibernate: select cliente0_.COD_CLI as COD_CLI0_, cliente0_.COD_CLASSE as COD_CLASSE0_, cliente0_.COD_CLI_EXT as COD_CLI_3_0_, cliente0_.COD_ORG as COD_ORG0_, cliente0_.DAT_INCLUSAO as DAT_INCL5_0_, cliente0_.DSC_EMAIL as DSC_EMAIL0_, cliente0_.IND_SITUA_FORNEC as IND_SITU7_0_, cliente0_.NOM_CLI as NOM_CLI0_, cliente0_.VLR_SLD_DEV as VLR_SLD_9_0_ from SSC_CLIENTE cliente0_ where cliente0_.COD_CLI=?
21:32:57,152 INFO  [STDOUT] Hibernate: select cliente0_.COD_CLI as COD_CLI0_, cliente0_.COD_CLASSE as COD_CLASSE0_, cliente0_.COD_CLI_EXT as COD_CLI_3_0_, cliente0_.COD_ORG as COD_ORG0_, cliente0_.DAT_INCLUSAO as DAT_INCL5_0_, cliente0_.DSC_EMAIL as DSC_EMAIL0_, cliente0_.IND_SITUA_FORNEC as IND_SITU7_0_, cliente0_.NOM_CLI as NOM_CLI0_, cliente0_.VLR_SLD_DEV as VLR_SLD_9_0_ from SSC_CLIENTE cliente0_ where cliente0_.COD_CLI=?
21:32:57,160 INFO  [STDOUT] Hibernate: select cliente0_.COD_CLI as COD_CLI0_, cliente0_.COD_CLASSE as COD_CLASSE0_, cliente0_.COD_CLI_EXT as COD_CLI_3_0_, cliente0_.COD_ORG as COD_ORG0_, cliente0_.DAT_INCLUSAO as DAT_INCL5_0_, cliente0_.DSC_EMAIL as DSC_EMAIL0_, cliente0_.IND_SITUA_FORNEC as IND_SITU7_0_, cliente0_.NOM_CLI as NOM_CLI0_, cliente0_.VLR_SLD_DEV as VLR_SLD_9_0_ from SSC_CLIENTE cliente0_ where cliente0_.COD_CLI=?
21:32:57,168 INFO  [STDOUT] Hibernate: select cliente0_.COD_CLI as COD_CLI0_, cliente0_.COD_CLASSE as COD_CLASSE0_, cliente0_.COD_CLI_EXT as COD_CLI_3_0_, cliente0_.COD_ORG as COD_ORG0_, cliente0_.DAT_INCLUSAO as DAT_INCL5_0_, cliente0_.DSC_EMAIL as DSC_EMAIL0_, cliente0_.IND_SITUA_FORNEC as IND_SITU7_0_, cliente0_.NOM_CLI as NOM_CLI0_, cliente0_.VLR_SLD_DEV as VLR_SLD_9_0_ from SSC_CLIENTE cliente0_ where cliente0_.COD_CLI=?
21:32:57,180 INFO  [STDOUT] Hibernate: select cliente0_.COD_CLI as COD_CLI0_, cliente0_.COD_CLASSE as COD_CLASSE0_, cliente0_.COD_CLI_EXT as COD_CLI_3_0_, cliente0_.COD_ORG as COD_ORG0_, cliente0_.DAT_INCLUSAO as DAT_INCL5_0_, cliente0_.DSC_EMAIL as DSC_EMAIL0_, cliente0_.IND_SITUA_FORNEC as IND_SITU7_0_, cliente0_.NOM_CLI as NOM_CLI0_, cliente0_.VLR_SLD_DEV as VLR_SLD_9_0_ from SSC_CLIENTE cliente0_ where cliente0_.COD_CLI=?
21:32:57,194 INFO  [STDOUT] Hibernate: select cliente0_.COD_CLI as COD_CLI0_, cliente0_.COD_CLASSE as COD_CLASSE0_, cliente0_.COD_CLI_EXT as COD_CLI_3_0_, cliente0_.COD_ORG as COD_ORG0_, cliente0_.DAT_INCLUSAO as DAT_INCL5_0_, cliente0_.DSC_EMAIL as DSC_EMAIL0_, cliente0_.IND_SITUA_FORNEC as IND_SITU7_0_, cliente0_.NOM_CLI as NOM_CLI0_, cliente0_.VLR_SLD_DEV as VLR_SLD_9_0_ from SSC_CLIENTE cliente0_ where cliente0_.COD_CLI=?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 03, 2004 8:31 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Use <key-property> and a <many-to-one insert="false" update="false"/> instead of <key-many-to-one/>


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 03, 2004 9:13 pm 
Beginner
Beginner

Joined: Fri Apr 16, 2004 10:25 am
Posts: 44
Location: Brazil
I changed the code but now It gives this error that I cant figure out


22:16:29,959 ERROR [Configuration] Could not compile the mapping document
net.sf.hibernate.MappingException: Could not determine a property type for: codCli
at net.sf.hibernate.cfg.Binder.bindProperty(Binder.java:455)
at net.sf.hibernate.cfg.Binder.createProperty(Binder.java:1081)
at net.sf.hibernate.cfg.Binder.bindComponent(Binder.java:869)
at net.sf.hibernate.cfg.Binder.bindRootClass(Binder.java:287)
at net.sf.hibernate.cfg.Binder.bindRoot(Binder.java:1256)
at net.sf.hibernate.cfg.Configuration.add(Configuration.java:252)
at net.sf.hibernate.cfg.Configuration.addInputStream(Configuration.java:288)
at net.sf.hibernate.cfg.Configuration.addResource(Configuration.java:336)
at net.sf.hibernate.cfg.Configuration.doConfigure(Configuration.java:1013)
at net.sf.hibernate.cfg.Configuration.doConfigure(Configuration.java:969)
at net.sf.hibernate.cfg.Configuration.configure(Configuration.java:897)
at net.sf.hibernate.cfg.Configuration.configure(Configuration.java:883)
at com.br.resource.csu.lembranca.dao.HibernateDaoFactory.openSession(HibernateDaoF
actory.java:26)
at com.br.resource.csu.lembranca.returnfase1.ReturnFase1FileProcessBean.gerarArqui
vo(ReturnFase1FileProcessBean.java:47)
at com.br.resource.csu.lembranca.jmx.LembrancaService.gerarArquivoRetornoFase1(Lem
brancaService.java:564)


Code:
    <class name="com.br.resource.csu.lembranca.dao.hibernate.persisted.Documento" table="SSC_documento">
        <composite-id name="docPK" class="com.br.resource.csu.lembranca.dao.hibernate.persisted.DocumentoPK">
         <key-property name="codCli" column="COD_CLI"/>
          <key-property name="inxDoc" column="INX_DOC"/>
        </composite-id>
      <set name="regras" inverse="true" lazy="true" cascade="all">
          <key>
             <column name="inx_doc"/>
             <column name="cod_cli"/>
          </key>
          <one-to-many class="com.br.resource.csu.lembranca.dao.hibernate.persisted.DocumentoRegra"/>
      </set>
      <many-to-one name="codCli"       column="COD_CLI" insert="false" update="false"/>
        <property name="codInstalacao"  column="COD_INSTALACAO"/>
        <property name="codLivroLeitura"        column="COD_LIVRO_LEITURA"/>
        <property name="codLocalidade"  column="COD_LOCALIDADE"/>
        <property name="codLoteFaturamento"     column="COD_LOTE_FATURAMENTO"/>
        <property name="codMotivoExc"   column="COD_MOTIVO_EXC"/>
        <property name="codTipoDoc"     column="COD_TIPO_DOC"/>









Code:
public class Documento implements Serializable{
   private DocumentoPK docPK;
   private Integer codTipoDoc;
   private Integer qtdTentativa;
   private String flgDebAut;
   private Date datFimCob;
   private Date datIniCob;
   private String codLocalidade;
   private String codLoteFaturamento;
   private String codInstalacao;
   private String codUnidOper;
   private String codLivroLeitura;
   private Date datExc;
   private String codMotivoExc;
   private Date datCriacaoFatura;
   private Float vlrFatura;
   private Date datVenctoFatura;
   private Date mesRefFatura;
   private String numFatura;
   private Date datInclusaoReg;
   private Date datProcArqOrg;
   private String indContencioso;
   private Date datPrevCorte;
   private Integer totFaturaAvisoDeb;
   private Date datEmissaoFatura;
   private Cliente codCli;
   private Integer inxDoc;
   private int diasAtraso;
   
   private Set regras;
   
   public static String CLASSE_RESIDENCIAL = "100";
   public static String CLASSE_COMERCIAL   = "200";
   public static String CLASSE_INDUSTRIAL  = "300";
   
........

   public DocumentoPK getDocPK() {
      return docPK;
   }
   public void setDocPK(DocumentoPK docPK) {
      this.docPK = docPK;
   }
   public int getDiasAtraso() {
      return diasAtraso;
   }
   public void setDiasAtraso(int diasAtraso) {
      this.diasAtraso = diasAtraso;
   }
    public Cliente getCodCli() {
        return codCli;
    }
    public void setCodCli(Cliente codCli) {
        this.codCli = codCli;
    }

    /**
     * @see java.lang.Object#hashCode()
     */
    public int hashCode() {
        return new HashCodeBuilder(-985567169, -1385580359).appendSuper(
                super.hashCode()).append(this.diasAtraso).append(
                this.datInclusaoReg).append(this.indContencioso).append(
                this.codCli).append(this.datVenctoFatura).append(this.regras)
                .append(this.numFatura).append(this.datProcArqOrg).append(
                        this.datPrevCorte).append(this.codLoteFaturamento)
                .append(this.datIniCob).append(this.docPK).append(
                        this.codMotivoExc).append(this.codLivroLeitura).append(
                        this.vlrFatura).append(this.qtdTentativa).append(
                        this.totFaturaAvisoDeb).append(this.codLocalidade)
                .append(this.mesRefFatura).append(this.datExc).append(
                        this.datFimCob).append(this.codTipoDoc).append(
                        this.datEmissaoFatura).append(this.inxDoc).append(
                        this.codInstalacao).append(this.datCriacaoFatura)
                .append(this.codUnidOper).append(this.flgDebAut).toHashCode();
    }
    /**
     * @see java.lang.Object#equals(Object)
     */
    public boolean equals(Object object) {
        if (!(object instanceof Documento)) {
            return false;
        }
        Documento rhs = (Documento) object;
        return new EqualsBuilder().appendSuper(super.equals(object)).append(
                this.diasAtraso, rhs.diasAtraso).append(this.datInclusaoReg,
                rhs.datInclusaoReg).append(this.indContencioso,
                rhs.indContencioso).append(this.codCli, rhs.codCli).append(
                this.datVenctoFatura, rhs.datVenctoFatura).append(this.regras,
                rhs.regras).append(this.numFatura, rhs.numFatura).append(
                this.datProcArqOrg, rhs.datProcArqOrg).append(
                this.datPrevCorte, rhs.datPrevCorte).append(
                this.codLoteFaturamento, rhs.codLoteFaturamento).append(
                this.datIniCob, rhs.datIniCob).append(this.docPK, rhs.docPK)
                .append(this.codMotivoExc, rhs.codMotivoExc).append(
                        this.codLivroLeitura, rhs.codLivroLeitura).append(
                        this.vlrFatura, rhs.vlrFatura).append(
                        this.qtdTentativa, rhs.qtdTentativa).append(
                        this.totFaturaAvisoDeb, rhs.totFaturaAvisoDeb).append(
                        this.codLocalidade, rhs.codLocalidade).append(
                        this.mesRefFatura, rhs.mesRefFatura).append(
                        this.datExc, rhs.datExc).append(this.datFimCob,
                        rhs.datFimCob).append(this.codTipoDoc, rhs.codTipoDoc)
                .append(this.datEmissaoFatura, rhs.datEmissaoFatura).append(
                        this.inxDoc, rhs.inxDoc).append(this.codInstalacao,
                        rhs.codInstalacao).append(this.datCriacaoFatura,
                        rhs.datCriacaoFatura).append(this.codUnidOper,
                        rhs.codUnidOper).append(this.flgDebAut, rhs.flgDebAut)
                .isEquals();
    }

}


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 03, 2004 9:35 pm 
Beginner
Beginner

Joined: Fri Apr 16, 2004 10:25 am
Posts: 44
Location: Brazil
I got it, inside DocumentoPK I had
Code:
public class DocumentoPK implements Serializable{

   private Cliente codCli;
   private Integer inxDoc;

   public Cliente getCodCli() {
      return codCli;
   }
   public void setCodCli(Cliente codCli) {
      this.codCli = codCli;
   }
   public Integer getInxDoc() {
      return inxDoc;
   }
   public void setInxDoc(Integer inxDoc) {
      this.inxDoc = inxDoc;
   }
   /**
    * @see java.lang.Object#equals(Object)
    */
   public boolean equals(Object object) {
      if (!(object instanceof DocumentoPK)) {
         return false;
      }
      DocumentoPK rhs = (DocumentoPK) object;
      return new EqualsBuilder().appendSuper(super.equals(object)).append(
            this.inxDoc, rhs.inxDoc).append(this.codCli, rhs.codCli)
            .isEquals();
   }
   /**
    * @see java.lang.Object#hashCode()
    */
   public int hashCode() {
      return new HashCodeBuilder(-989174175, 990056475).appendSuper(
            super.hashCode()).append(this.inxDoc).append(this.codCli)
            .toHashCode();
   }
}


Instead of

Code:
public class DocumentoPK implements Serializable{

   private Integer codCli;
   private Integer inxDoc;

    public Integer getCodCli() {
        return codCli;
    }
    public void setCodCli(Integer codCli) {
        this.codCli = codCli;
    }
   public Integer getInxDoc() {
      return inxDoc;
   }
   public void setInxDoc(Integer inxDoc) {
      this.inxDoc = inxDoc;
   }
   /**
    * @see java.lang.Object#equals(Object)
    */
   public boolean equals(Object object) {
      if (!(object instanceof DocumentoPK)) {
         return false;
      }
      DocumentoPK rhs = (DocumentoPK) object;
      return new EqualsBuilder().appendSuper(super.equals(object)).append(
            this.inxDoc, rhs.inxDoc).append(this.codCli, rhs.codCli)
            .isEquals();
   }
   /**
    * @see java.lang.Object#hashCode()
    */
   public int hashCode() {
      return new HashCodeBuilder(-989174175, 990056475).appendSuper(
            super.hashCode()).append(this.inxDoc).append(this.codCli)
            .toHashCode();
   }
}


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 03, 2004 9:57 pm 
Beginner
Beginner

Joined: Fri Apr 16, 2004 10:25 am
Posts: 44
Location: Brazil
in fact I cannot do that.
I need it as a class.
but it seems that hibernate doesnt recognize the class

Code:
    <class name="com.br.resource.csu.lembranca.dao.hibernate.persisted.Documento" table="SSC_documento">
        <composite-id name="docPK" class="com.br.resource.csu.lembranca.dao.hibernate.persisted.DocumentoPK">
         <key-property name="codCli" type="com.br.resource.csu.lembranca.dao.hibernate.persisted.Cliente" column="COD_CLI"/>
          <key-property name="inxDoc" column="INX_DOC"/>
        </composite-id>
      <set name="regras" inverse="true" lazy="true" cascade="all">
          <key>
             <column name="inx_doc"/>
             <column name="cod_cli"/>
          </key>
          <one-to-many class="com.br.resource.csu.lembranca.dao.hibernate.persisted.DocumentoRegra"/>
      </set>
      <many-to-one name="codCli"       column="COD_CLI" insert="false" update="false"/>
        <property name="codInstalacao"  column="COD_INSTALACAO"/>
        <property name="codLivroLeitura"        column="COD_LIVRO_LEITURA"/>
        <property name="codLocalidade"  column="COD_LOCALIDADE"/>
        <property name="codLoteFaturamento"     column="COD_LOTE_FATURAMENTO"/>



Code:
public class DocumentoPK implements Serializable{

   private Cliente codCli;
   private Integer inxDoc;

   
    public Cliente getCodCli() {
        return codCli;
    }
    public void setCodCli(Cliente codCli) {
        this.codCli = codCli;
    }
   public Integer getInxDoc() {
      return inxDoc;
   }
   public void setInxDoc(Integer inxDoc) {
      this.inxDoc = inxDoc;
   }
   /**
    * @see java.lang.Object#equals(Object)
    */
   public boolean equals(Object object) {
      if (!(object instanceof DocumentoPK)) {
         return false;
      }
      DocumentoPK rhs = (DocumentoPK) object;
      return new EqualsBuilder().appendSuper(super.equals(object)).append(
            this.inxDoc, rhs.inxDoc).append(this.codCli, rhs.codCli)
            .isEquals();
   }
   /**
    * @see java.lang.Object#hashCode()
    */
   public int hashCode() {
      return new HashCodeBuilder(-989174175, 990056475).appendSuper(
            super.hashCode()).append(this.inxDoc).append(this.codCli)
            .toHashCode();
   }
}


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 03, 2004 10:07 pm 
Beginner
Beginner

Joined: Fri Apr 16, 2004 10:25 am
Posts: 44
Location: Brazil
forget the last post, that was wrong, it was my HQL that was wrong

it was :
colDoc = session.find("select doc from Documento doc " +
"inner join fetch doc.docPK.codCli cliente " +
"inner join fetch doc.docPK.codCli.codOrg org");
and it should be :
colDoc = session.find("select doc from Documento doc " +
"inner join fetch doc.docPK.codCli cliente " +
"inner join fetch doc.codCli.codOrg org");


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 06, 2004 6:07 pm 
Beginner
Beginner

Joined: Fri Apr 16, 2004 10:25 am
Posts: 44
Location: Brazil
Is there anything else that I have to do (or take care) about this?

cause I still having this kind of problem in another part of my application, althought I'm not using <key-many-to-one> anywhere


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 06, 2004 7:15 pm 
Beginner
Beginner

Joined: Fri Apr 16, 2004 10:25 am
Posts: 44
Location: Brazil
is this right ?

Code:
    <class name="com.br.resource.csu.lembranca.dao.hibernate.persisted.DocumentoRegra" table="SSC_rel_doc_regra">
        <composite-id class="com.br.resource.csu.lembranca.dao.hibernate.persisted.DocumentoRegraPK">
         <key-property name="inxRegraCampanha"    column="inx_regra_campanha"/>
           <key-property name="codCli"          column="COD_CLI"/>
           <key-property name="inxDoc"          column="inx_doc"/>
        </composite-id>
        <many-to-one name="doc" insert="false" update="false">
           <column name="COD_CLI"/>
           <column name="inx_doc"/>
        </many-to-one>
        <many-to-one name="inxRegraCampanha" column="inx_regra_campanha" insert="false" update="false"/>
        <property    name="datAplicaRegra"   column="dat_aplica_regra"/>
        <property    name="datPrevRegra"     column="dat_prev_regra"/>
        <property    name="indStatusRegra"   column="ind_status_regra"/>
        <property    name="vlrResultRegra"   column="vlr_result_regra"/>
        <property    name="dscObs"           column="dsc_obs"/>
        <property    name="flgAtualizacao"   column="FLG_ATUALIZACAO"/>
    </class>



Code:
   <class name="com.br.resource.csu.lembranca.dao.hibernate.persisted.Documento" table="SSC_documento">
        <composite-id name="docPK" class="com.br.resource.csu.lembranca.dao.hibernate.persisted.DocumentoPK">
         <key-property name="codCli" column="COD_CLI"/>
          <key-property name="inxDoc" column="INX_DOC"/>
        </composite-id>
      <set name="regras" inverse="true" lazy="true" cascade="all">
          <key>
             <column name="inx_doc"/>
             <column name="cod_cli"/>
          </key>
          <one-to-many class="com.br.resource.csu.lembranca.dao.hibernate.persisted.DocumentoRegra"/>
      </set>
      <many-to-one name="codCli"       column="COD_CLI" insert="false" update="false"/>
        <property name="codInstalacao"  column="COD_INSTALACAO"/>
        <property name="codLivroLeitura"        column="COD_LIVRO_LEITURA"/>
        <property name="codLocalidade"  column="COD_LOCALIDADE"/>
        <property name="codLoteFaturamento"     column="COD_LOTE_FATURAMENTO"/>
        <property name="codMotivoExc"   column="COD_MOTIVO_EXC"/>
        <property name="codTipoDoc"     column="COD_TIPO_DOC"/>
        <property name="codUnidOper"    column="COD_UNID_OPER"/>
        <property name="datCriacaoFatura"       column="DAT_CRIACAO_FATURA"/>
        <property name="datEmissaoFatura"       column="DAT_EMISSAO_FATURA"/>
        <property name="datExc" column="DAT_EXC"/>
        <property name="datFimCob"      column="DAT_FIM_COB"/>
        <property name="datInclusaoReg" column="DAT_INCLUSAO_REG"/>
        <property name="datIniCob"      column="DAT_INI_COB"/>
        <property name="datPrevCorte"   column="DAT_PREV_CORTE"/>
        <property name="datProcArqOrg"  column="DAT_PROC_ARQ_ORG"/>
        <property name="datVenctoFatura"        column="DAT_VENCTO_FATURA"/>
        <property name="flgDebAut"      column="FLG_DEB_AUT"/>
        <property name="indContencioso" column="IND_CONTENCIOSO"/>
        <property name="mesRefFatura"   column="MES_REF_FATURA"/>
        <property name="numFatura"      column="NUM_FATURA"/>
        <property name="qtdTentativa"   column="QTD_TENTATIVA"/>
        <property name="totFaturaAvisoDeb"      column="TOT_FATURA_AVISO_DEB"/>
        <property name="vlrFatura"      column="VLR_FATURA"/>
    </class>



Code:
    <class name="com.br.resource.csu.lembranca.dao.hibernate.persisted.RegraCampanha" table="SSC_rel_regra_campanha">
      <id name="inxRegraCampanha" column="inx_regra_campanha" type="integer">
         <generator class="increment"/>
      </id>
       <many-to-one  name="codCampanha"     column="cod_campanha"/>
        <property name="codCampanhaDiscador" column="cod_campanha_discador"/>
        <many-to-one name="codRegra"         column="cod_regra"/>
        <property name="flgAtivo"            column="flg_ativo"/>
        <property name="nomObjExec"          column="nom_obj_exec"/>
        <property name="numOrdem"            column="num_ordem"/>
    </class>


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

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.