-->
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.  [ 3 posts ] 
Author Message
 Post subject: How Can I map these code ?
PostPosted: Tue Jun 22, 2004 11:20 am 
Newbie

Joined: Thu Nov 13, 2003 2:49 pm
Posts: 2
Hello, I have a model following below.
Image

My Java code is

Code:
public class People implements Serializable {
   private int id;
   private String nome;
   private String telefone;
   private String endereco;
   private java.util.List telefones;
   private Dep departamento;
getters and setters for all fiels.
//

public class Phone implements Serializable {
   
   private People pessoa;
   private TP_Phone tipoTelefone;
   private int ddd;
   private String numero;

public class Dep implements Serializable {

   private int codigo;
   private String nome;

public class TP_Phone implements Serializable{
   private int codigo;
   private String nome;


How can I map these code ? Because the hibernate throw an Exception
"Caused by: net.sf.hibernate.MappingException: Foreign key (telefone [cod_pessoa])) must have same number of columns as the referenced primary key (pessoa [cod_depart,codigo])"

Thank very much!!!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 22, 2004 11:34 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
show mapping files

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 22, 2004 11:43 am 
Newbie

Joined: Thu Nov 13, 2003 2:49 pm
Posts: 2
The mapping files:

Code:
<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE hibernate-mapping PUBLIC
   "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
   "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
   
<hibernate-mapping>
   <class name="br.eti.alessandro.modelo.People" table="pessoa">
      <id name="id" column="codigo" type="integer" unsaved-value="0">         
         <generator class="native"/>
      </id>
      
      <many-to-one name="departamento" class="br.eti.alessandro.modelo.Dep"
            column="cod_depart" unique="true"/>
      
      <set
         name="emails"  table="emails"
         lazy="false" inverse="true"
        cascade="all"     sort="unsorted">   
                
          <key column="cod_Pessoa"/>     
          <one-to-many  class="br.eti.alessandro.modelo.Email"/>
       </set>           
         
       
       <list name="telefones" table="telefone">
            <key column="cod_pessoa"/>
            <index column="cod_pessoa,cod_tipo"/>
           
            <composite-element class="br.eti.alessandro.modelo.Phone">
               <property name="ddd"     type="int"/>
               <property name="numero"  type="string"/>
            </composite-element>
       </list>         
       
      <property name="nome" not-null="true"/>
      <property name="endereco" not-null="false"/>
      <property name="telefone" not-null="false"/>
      
   </class>
</hibernate-mapping>

<!---------------------------------------------------------------------------------->
<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE hibernate-mapping PUBLIC
   "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
   "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
   
<hibernate-mapping>
   <class name="br.eti.alessandro.modelo.Dep" table="departamento">
      <id name="codigo" column="cod_depart" type="integer" unsaved-value="0">         
         <generator class="native"/>
       </id>         
      <property name="nome" column="departamento" type="string" not-null="true"/>
   
   
   <list name="pessoas" table="pessoa" lazy="true">
      <key column="cod_depart"/>
      <index column="codigo"/>
      <composite-element class="br.eti.alessandro.modelo.People">
         <property name="nome"      type="string" />
         <property name="endereco"  type="string" />
         <property name="telefone"  type="string" />         
      </composite-element>
   </list>
   
   </class>
   
</hibernate-mapping>
<!---------------------------------------------------------------------------------->
<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE hibernate-mapping PUBLIC
   "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
   "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
   
<hibernate-mapping>
   <class name="br.eti.alessandro.modelo.Phone" table="telefone">
      <composite-id>
         <key-many-to-one column="cod_pessoa" name="pessoa"       class="br.eti.alessandro.modelo.People"/>
         <key-many-to-one column="cod_tipo"   name="tipoTelefone" class="br.eti.alessandro.modelo.Tp_Phone"/>         
         
        </composite-id>                          
      
      <property name="ddd"      column="ddd"     type="integer"    not-null="false"/>
      <property name="numero"   column="numero"  type="string" not-null="true"/>
</class>
      
</hibernate-mapping>

<!---------------------------------------------------------------------------------->



<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE hibernate-mapping PUBLIC
   "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
   "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
   
<hibernate-mapping>
   <class name="br.eti.alessandro.modelo.Tp_Phone" table="tp_telefone">
      <id name="codigo" column="codigo" type="integer" unsaved-value="0">         
         <generator class="native"/>
       </id>         
      <property name="nome" column="tipo" type="string" not-null="true"/>
   </class>
</hibernate-mapping>
<!---------------------------------------------------------------------------------->
<!DOCTYPE hibernate-mapping PUBLIC
   "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
   "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
   
<hibernate-mapping>
   <class name="br.eti.alessandro.modelo.Email" table="emails">
      <id name="codigo" column="codigo" type="integer" unsaved-value="0">
         <generator class="native"/>
      </id>
      <property name="nome" not-null="true"/>      
   </class>
</hibernate-mapping>
   


Thank you.


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