-->
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.  [ 2 posts ] 
Author Message
 Post subject: Help with mapping (set
PostPosted: Mon Oct 24, 2005 7:28 am 
Regular
Regular

Joined: Mon Aug 29, 2005 9:46 am
Posts: 102
Hibernate version: 3.0

Hello everyone,
I'm having problems writing a part of a mapping. First of all, I have these mappings:
Code:
  <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
         "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
 
<hibernate-mapping>
    <class name="auge.bean.MpProducao" table="MPPRODUCAO" >
        <composite-id>
            <key-many-to-one name="materia" column="materia" class="auge.bean.MateriaPrima"
                    lazy="false"/>       
            <key-property name="numeroOrdemItens" column="numeroOrdemItens" type="java.lang.Integer"/>
        </composite-id>         
        <property name="quantidade" column="quantidade" type="java.lang.Float" />
        <property name="baixaDada" column="baixaDada" type="java.lang.Integer" />
       
       <many-to-one name="cor" column="cor" class="auge.bean.Cor"
                    not-null="false" lazy="false"/>   
                   
    </class>   
</hibernate-mapping>


Code:
  <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
         "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
 
<hibernate-mapping>
    <class name="auge.bean.OrdemItens" table="ORDEMITENS" >
       <id name="numeroOrdemItens" column="numeroOrdemItens" type="java.lang.Integer">
           <generator class="assigned"/>
       </id>           
       <property name="tamanho" column="tamanho" type="java.lang.String" />
       <property name="qtdePedida" column="qtdePedida" type="java.lang.Integer" />                           
       <property name="qtdeFabricar" column="qtdeFabricar" type="java.lang.Integer" />
       <property name="processoAtivo" column="processoAtivo" type="java.lang.Integer" />       
       
       <many-to-one name="ordemDeProducao" column="numeroOrdem" class="auge.bean.OrdemDeProducao"
                    not-null="false" lazy="false"/>       
                   
       <many-to-one name="produto" column="produto" class="auge.bean.Produto"
                    not-null="false" lazy="false"/>       

       <many-to-one name="cor" column="cor" class="auge.bean.Cor"
                    not-null="false" lazy="false"/>       
    </class>
</hibernate-mapping>


I'm trying to put into the second mapping (auge.bean.OrdemItens) a set of the first one. I've tried it this way:

Code:
       <set name="mpProducao" inverse="true" cascade="all" >
            <key>
                <column name="numeroOrdemItens"></column>
                <column name="materia"></column>
            </key>
            <one-to-many class="auge.bean.MpProducao" />
        </set>                     


But I get an error saying: Foreign key (FKC24B75B6576D388F:MPPRODUCAO [numeroOrdemItens,materia])) must have same number of columns as the referenced primary key (ORDEMITENS [numeroOrdemItens])


What's wrong? Thanks for the help

_________________
Don't forget to rate if the post helped!


Top
 Profile  
 
 Post subject: key
PostPosted: Mon Oct 24, 2005 11:59 am 
Expert
Expert

Joined: Fri Jul 22, 2005 2:42 pm
Posts: 670
Location: Seattle, WA
Key points to the collection table points to primary key in the master table

http://www.hibernate.org/hib_docs/v3/re ... tions.html

and because PK is only one column

<class name="auge.bean.OrdemItens" table="ORDEMITENS" >
<id name="numeroOrdemItens" column="numeroOrdemItens" type="java.lang.Integer">
<generator class="assigned"/>
</id>

the key in the collection should point to this PK like this

<set name="mpProducao" inverse="true" cascade="all" >
<key>
<column name="numeroOrdemItens"></column>
</key>
<one-to-many class="auge.bean.MpProducao" />
</set>

_________________
--------------
Konstantin

SourceLabs - dependable OpenSource systems


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