-->
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.  [ 4 posts ] 
Author Message
 Post subject: Different number of columns in collection relationships
PostPosted: Tue May 16, 2006 11:32 am 
Beginner
Beginner

Joined: Tue Dec 21, 2004 11:53 am
Posts: 42
Hello there! We're facing a huge problem here. Our DB model (from our costumer) is a total mess.

I have two classes

Class A{

Pk (a composite made of cityCode, contractNumber, point, recCode)
property progCode;
Set B;
}

Class B{

Pk(a composite made of cityCode, progCode)

}



The problem is, how to map the Class A set to Class B?

The number of the columns is differentm and Class B does not have such column as contractNumber.

Is it possible to force a collection mapping to have different number of columns between Parent and Child relation?

Regards


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 16, 2006 12:09 pm 
Expert
Expert

Joined: Tue Apr 25, 2006 12:04 pm
Posts: 260
I never worked with such an example. Could you try with the mapping files, if you havent yet.

Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping package="learn.hibernate">
   <class name="ClassA" table="TABLE_A" >
      <composite-id>
         <key-property name="cityCode"/>
         <key-property name="contractNumber"/>
         <key-property name="point" />
         <key-property name="recCode"/>
      </composite-id> 
     
      <property name="progCode"/>

      <many-to-one name="classBObject" class="ClassB" insert="false" update="false">
         <column name="cityCode"/>
         <column name="progCode"/>
      </many-to-one>
    </class>

   <class name="ClassB" table="TABLE_B" >
      <composite-id>
         <key-property name="cityCode"/>
         <key-property name="progCode"/>
      </composite-id> 

      <set name="classASet" >
    <key>
      <column name="cityCode"/>
      <column name="progCode"/>
    </key>
    <one-to-many class="ClassA"/>
      </set>
    </class>
</hibernate-mapping>



Top
 Profile  
 
 Post subject:
PostPosted: Tue May 16, 2006 1:32 pm 
Beginner
Beginner

Joined: Tue Dec 21, 2004 11:53 am
Posts: 42
It's kind like this:

Code:
<hibernate-mapping
>
    <class
        name="com.waybrasil.model.persistence.pontoproduto.PontoProduto"
        table="VW_SOA_PONTO_PRODUTO"
    >

        <composite-id
            name="pk"
            class="com.waybrasil.model.persistence.pontoproduto.PontoProdutoPK"
        >
                     <key-property
                        name="codigoReceita"
                        type="com.waybrasil.model.enums.CodigoReceitaEnum"
                        column="CODREC"
                />

                     <key-property
                        name="cidade"
                        type="java.lang.Integer"
                        column="CODCID"
                />

                     <key-property
                        name="contrato"
                        type="java.lang.Integer"
                        column="CONTRA"
                />

                     <key-property
                        name="ponto"
                        type="java.lang.Integer"
                        column="PONTO"
                />

        </composite-id>

        <property
            name="codigoProgramacao"
            type="java.lang.Integer"
            update="true"
            insert="true"
            column="CODPROG"
        />

        <property
            name="dataConexao"
            type="java.util.Date"
            update="true"
            insert="true"
            column="DTCONE"
        />

        <property
            name="dataDesconexao"
            type="java.util.Date"
            update="true"
            insert="true"
            column="DTDESC"
        />

        <property
            name="descricao"
            type="java.lang.String"
            update="true"
            insert="true"
            column="DESCPROG"
        />

        <property
            name="lancamento"
            type="java.lang.String"
            update="true"
            insert="true"
            column="LACAMENTO"
        />

        <property
            name="local"
            type="java.lang.String"
            update="true"
            insert="true"
            column="LOCAL"
        />

        <property
            name="statusConexao"
            type="com.waybrasil.model.enums.SituacaoContratoEnum"
            update="true"
            insert="true"
            column="CODSIT"
        />

        <property
            name="valor"
            type="java.lang.Double"
            update="true"
            insert="true"
            column="VALOR"
        />

        <property
            name="valorAluguel"
            type="java.lang.Double"
            update="true"
            insert="true"
            column="VALOR_ALUGUEL"
        />

        <property
            name="dataUltimaAtualizacao"
            type="java.util.Date"
            update="true"
            insert="true"
            column="DTULTALT"
        />

        <property
            name="permiteDowngrade"
            type="com.waybrasil.model.enums.SimNaoEnum"
            update="true"
            insert="true"
            column="FLAGALT"
        />

     

        <!--
            To add non XDoclet property mappings, create a file named
                hibernate-properties-PontoProduto.xml
            containing the additional properties and place it in your merge dir.
        -->

    </class>

</hibernate-mapping>


<hibernate-mapping
>
    <class
        name="com.waybrasil.model.persistence.pacote.Pacote"
        table="VW_SOA_PACOTE"
    >

        <composite-id
            name="pk"
            class="com.waybrasil.model.persistence.pacote.PacotePK"
        >
                     <key-property
                        name="codigoPacote"
                        type="java.lang.Integer"
                        column="CODPROG"
                />

                     <key-property
                        name="codigoCidade"
                        type="java.lang.Integer"
                        column="CODCID"
                />

        </composite-id>

        <property
            name="ativo"
            type="com.waybrasil.model.enums.SimNaoEnum"
            update="true"
            insert="true"
            column="ATIVO"
        />

        <property
            name="codigoReceita"
            type="com.waybrasil.model.enums.CodigoReceitaEnum"
            update="true"
            insert="true"
            column="CODREC"
        />

        <property
            name="descricao"
            type="java.lang.String"
            update="true"
            insert="true"
            column="DESCPROG"
        />

        <property
            name="tipoPonto"
            type="com.waybrasil.model.enums.TipoPontoEnum"
            update="true"
            insert="true"
            column="TPONTO"
        />

        <property
            name="valor"
            type="java.lang.Double"
            update="true"
            insert="true"
            column="VALOR"
        />

        <property
            name="categoria"
            type="com.waybrasil.model.enums.CategoriaPlanoEnum"
            update="true"
            insert="true"
            column="CATEGORIA"
        />

        <property
            name="quantidade"
            type="java.lang.Integer"
            update="true"
            insert="true"
            column="QTDE"
        />

        <property
            name="codigoGrupoServico"
            type="java.lang.Integer"
            update="true"
            insert="true"
            column="CODGRSER"
        />

        <!--
            To add non XDoclet property mappings, create a file named
                hibernate-properties-Pacote.xml
            containing the additional properties and place it in your merge dir.
        -->

    </class>

</hibernate-mapping>



And I'd like to have PontoProduto to have a one-to-many relationship with Pacote.

any ideas?

Best Regards


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 16, 2006 2:08 pm 
Expert
Expert

Joined: Tue Apr 25, 2006 12:04 pm
Posts: 260
I still dont understand that if you did tried to have <set> element as I mentioned before.

If you havent tried, do add <set> element in your PontoProduto class. For bi-directional also add <many-to-one> to Pacote.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.