-->
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.  [ 5 posts ] 
Author Message
 Post subject: Composite-Id. Help! I'm all messed up.
PostPosted: Sun Feb 04, 2007 5:04 am 
Newbie

Joined: Fri Feb 02, 2007 8:32 pm
Posts: 5
OK. First. Let me show you the diagram.


Image

Explanation:
The table Tipos_Documento has Different Identification Types for Patients. Id: IdTipoDocumento
The table Pacientes has Patient's personal information. Id: IdPacientes.
The table Pacientes_Documentos has Identifications that the patients have. Since they can have more than one, i use this table.

By meaning Identification, i'm talking about Driver's Licence, or different documents that help identify a person. SO. the user can insert more than one identification for each patient.

As you can see, the table Pacientes_Documentos, Has two Foreign Keys. One Is the Patient ID (IdPaciente) and the other is the Identification type (IdTipoDocumento). This two make a unique record. So, each Patient can have as many Identifications as Identification types are on the Tipos_Documentos table has.

So...
Here is the maping of the classes.

TipoDocumento (for table Tipos_Documentos)
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
  <class name="Negocios.TipoDocumento, Capas" table="Tipos_Documento">
    <id name="Id" column="IdTipoDocumento" type="int">
      <generator class="assigned" />
    </id>

    <property name="Nombre" />

  </class>
</hibernate-mapping>


Paciente (for table Pacientes)
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
  <class name="Negocios.Medicina.Paciente, Capas" table="Pacientes">
    <id name="Id" column="IdPaciente" type="int">
      <generator class="assigned" />
    </id>

    <property name="Nombre" />
    <property name="Apellido" />
    <property name="DomicilioCalle" column="DomCalle" />
    <property name="DomicilioNumero" column="DomNumero" />
    <property name="DomicilioMonoblock" column="DomMonoblock" />
    <property name="DomicilioPiso" column="DomPiso" />
    <property name="DomicilioDepartamento" column="DomDepartamento" />
    <property name="DomicilioCiudad" column="DomCiudad" />
    <property name="DomicilioProvincia" column="DomProvincia" />
    <property name="DomicilioPais" column="DomPais" />
    <property name="Sexo" column="Sexo" />

    <set name="Documentos" cascade="all" lazy="true">
      <key column="IdPaciente" />
      <one-to-many class="Negocios.Medicina.PacienteDocumento, Capas" />
    </set>

  </class>
</hibernate-mapping>


Paciente_Documento (for table Pacientes_Documentos)
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
  <class name="Negocios.Medicina.PacienteDocumento, Capas" table="Pacientes_Documentos">
    <composite-id>
      <key-many-to-one name="IdPaciente" class="Negocios.Medicina.Paciente, Capas" column="IdPaciente" />
      <key-many-to-one name="IdTipoDocumento" class="Negocios.TipoDocumento, Capas"  column="IdTipoDocumento"/>
    </composite-id>

    <property name="NumeroDocumento" column="Numero" />


  </class>
</hibernate-mapping>


So... on the Paciente Class, there is the property Documentos, which is an IDictionary. It would be the collection of Identifications, the patient has.

It worked really well before i added this new property.
But now, when I run my GetPaciente Method, I get the following error:

Quote:
Invalid mapping information specified for type Negocios.Medicina.Paciente, check your mapping file for property type mismatches


As i said before, it worked really great before adding this new property. So, I guess the problem must be on the way i'm relating the tables.

Can any of you give me a hand?

Please let me know if you need something else to figure it out.

Thanks in advance!

Juanu


Top
 Profile  
 
 Post subject: Re: Composite-Id. Help! I'm all messed up.
PostPosted: Sun Feb 04, 2007 3:18 pm 
Expert
Expert

Joined: Thu Jan 19, 2006 4:29 pm
Posts: 348
Juanu wrote:
So... on the Paciente Class, there is the property Documentos, which is an IDictionary.

If You use <set> in mapping, You must use IEsi.Collections.ISet for property type. If You want use IDictionary, use <map> in mapping (I think, not much experience with dictionary mapping....)

Gert

_________________
If a reply helps You, rate it!


Top
 Profile  
 
 Post subject:
PostPosted: Sun Feb 04, 2007 3:27 pm 
Newbie

Joined: Fri Feb 02, 2007 8:32 pm
Posts: 5
Hmm..
I see..
Any example on how to use it?


Top
 Profile  
 
 Post subject: Any News about that?
PostPosted: Thu Jun 07, 2007 11:21 am 
Newbie

Joined: Thu Jun 07, 2007 11:16 am
Posts: 1
I am with the same problem, but i'm using bag instead of set or map!

Did you already solve it?

[]'s


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 12, 2007 12:38 pm 
Newbie

Joined: Tue May 08, 2007 11:52 am
Posts: 6
I don't know if it helps you, but check the post :

http://forum.hibernate.org/viewtopic.ph ... ompositeid

I had the same problem and i resolved like it is in the post. I don't know if is the best way, but it works. ;)

If it helps you, please credit it. ;)


Nassa


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