Hola a todos! Necesito que me ayuden con un problemita que estoy
teniendo con NHibernate.
Tengo una estructura de BD que ya esta siendo utilizada y no puedo
modificar.
Tengo una Tabla HORARIOS_EMPLEADOS con PK ID_HORARIO y una tabla
DETALLES_HORARIOS con una PK compuesta por ID_HORARIO (FK a la tabla
HORARIOS) y un nro entero CONTADOR.
Para poder definir la PK compuesta hice lo siguiente:
1º Cree una clase Detalles_Horarios_Id que contiene como propiedades
un puntero a la clase Horarios y un int contador
2º En la clase Detalles_Horarios tiene un puntero Id a la clase
Detalles_Horarios_Id
Al tratar de ejecutar el proyecto me salta una excepcion en la línea:
ISessionFactory sesiones =
cfg.BuildSessionFactory();
La expción es:
Foreign key (FK89F661253744DF2A:T_HORARIOS_EMPLEADOS [idHorario]))
must have same number of columns as the referenced primary key
(T_DETALLES_HORARIOS [ID_HORARIO, CONTADOR])
Los archivos de mapeo y clases son los siguientes:
**************************************Clase Horarios_Empleados
**********************************
using System;
using System.Collections.Generic;
using System.Text;
namespace ClasesDelDominio
{
class Horarios_Empleados
{
public Horarios_Empleados()
{
}
public Horarios_Empleados(string des, DateTime fa, string l,
string ua)
{
Descripcion = des;
fecha_alta = fa;
libre = l;
usuario_alta = ua;
}
private int id_horario;
protected virtual int Id_horario
{
get { return id_horario; }
set { id_horario = value; }
}
private List<Detalles_Horarios> detalles;
protected virtual List<Detalles_Horarios> Detalles
{
get { return detalles; }
set { detalles = value; }
}
private string descripcion;
protected virtual string Descripcion
{
get { return descripcion; }
set { descripcion = value; }
}
private string usuario_alta;
protected virtual string Usuario_alta
{
get { return usuario_alta; }
set { usuario_alta = value; }
}
private DateTime fecha_alta;
protected virtual DateTime Fecha_alta
{
get { return fecha_alta; }
set { fecha_alta = value; }
}
private string usuario_modif;
protected virtual string Usuario_modif
{
get { return usuario_modif; }
set { usuario_modif = value; }
}
private DateTime? fecha_modif;
protected virtual DateTime? Fecha_modif
{
get { return fecha_modif; }
set { fecha_modif = value; }
}
private string libre;
protected virtual string Libre
{
get { return libre; }
set { libre = value; }
}
}
}
********************************************************************************************************
*************************************************Clase
Detalles_Horarios **************************
using System;
using System.Collections.Generic;
using System.Text;
namespace ClasesDelDominio
{
class Detalles_Horarios
{
private Detalles_Horarios_Id id;
public Detalles_Horarios_Id Id
{
get { return id; }
set { id = value; }
}
private string hora_entrada;
protected virtual string Hora_entrada
{
get { return hora_entrada; }
set { hora_entrada = value; }
}
private string hora_salida;
protected virtual string Hora_salida
{
get { return hora_salida; }
set { hora_salida = value; }
}
private string lunes;
protected virtual string Lunes
{
get { return lunes; }
set { lunes = value; }
}
private string martes;
protected virtual string Martes
{
get { return martes; }
set { martes = value; }
}
private string miercoles;
protected virtual string Miercoles
{
get { return miercoles; }
set { miercoles = value; }
}
private string jueves;
protected virtual string Jueves
{
get { return jueves; }
set { jueves = value; }
}
private string viernes;
protected virtual string Viernes
{
get { return viernes; }
set { viernes = value; }
}
private string sabado;
protected virtual string Sabado
{
get { return sabado; }
set { sabado = value; }
}
private string domingo;
protected virtual string Domingo
{
get { return domingo; }
set { domingo = value; }
}
private int minutos_tolerancia;
protected virtual int Minutos_tolerancia
{
get { return minutos_tolerancia; }
set { minutos_tolerancia = value; }
}
private DateTime fecha_desde;
protected virtual DateTime Fecha_desde
{
get { return fecha_desde; }
set { fecha_desde = value; }
}
private DateTime? fecha_hasta;
protected virtual DateTime? Fecha_hasta
{
get { return fecha_hasta; }
set { fecha_hasta = value; }
}
private string usuario_alta;
protected virtual string Usuario_alta
{
get { return usuario_alta; }
set { usuario_alta = value; }
}
private DateTime fecha_alta;
protected virtual DateTime Fecha_alta
{
get { return fecha_alta; }
set { fecha_alta = value; }
}
private string usuario_modif;
protected virtual string Usuario_modif
{
get { return usuario_modif; }
set { usuario_modif = value; }
}
private DateTime? fecha_modif;
protected virtual DateTime? Fecha_modif
{
get { return fecha_modif; }
set { fecha_modif = value; }
}
public override bool Equals (object obj)
{
if (obj == null || GetType() != obj.GetType())
{
return false;
}
if ((this.Id.Contador == ((Detalles_Horarios)obj).Id.Contador)
&& this.Id.Horario.Equals(((Detalles_Horarios)obj).Id.Horario))
return true;
else return false;
}
public override int GetHashCode()
{
int hash = 13;
hash += (null == this.Id.Contador ? 0 :
this.Id.Contador.GetHashCode());
hash += (null == this.Id.Horario ? 0 :
this.Id.Horario.GetHashCode());
return hash;
}
}
}
***************************************************************************************************
************************************Clase
Detalles_Empleados_Id****************************
using System;
using System.Collections.Generic;
using System.Text;
using ClasesDelDominio;
namespace ClasesDelDominio
{
class Detalles_Horarios_Id
{
public Detalles_Horarios_Id()
{
}
public Detalles_Horarios_Id(Horarios_Empleados h, int c)
{
this.horario = h;
this.contador = c;
}
private Horarios_Empleados horario;
public Horarios_Empleados Horario
{
get { return horario; }
set { horario = value; }
}
private int contador;
public int Contador
{
get { return contador; }
set { contador = value; }
}
public override bool Equals(object obj)
{
if (obj == null || GetType() != obj.GetType())
{
return false;
}
if ((this.Contador ==
((Detalles_Horarios_Id)obj).Contador) &&
this.Horario.Equals(((Detalles_Horarios_Id)obj).Horario))
return true;
else return false;
}
public override int GetHashCode()
{
int hash = 13;
hash += (null == this.Contador ? 0 :
this.Contador.GetHashCode());
hash += (null == this.Horario ? 0 :
this.Horario.GetHashCode());
return hash;
}
}
}
********************************************************************************************************
*********************************Mapeo
Horarios_Empleados.hbm.xml***************************
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
assembly="Ausentismo"
namespace="Ausentismo.ClasesDelDominio">
<class name="Horarios_Empleados" table="T_HORARIOS_EMPLEADOS">
<id name="Id_horario" type="int" unsaved-value="0">
<column name="ID_HORARIO" sql-type="number"/>
<generator class="sequence">
<param name="sequence">ID_HORARIO</param>
</generator>
</id>
<property name="Descripcion" column="DESCRIPCION" type="string"/>
<property name="Fecha_alta" column="FECHA_ALTA" type="DateTime" />
<property name="Fecha_modif" column="FECHA_MODIF" type="DateTime" /
>
<property name="Libre" column="LIBRE" type="string" />
<property name="Usuario_alta" column="USUARIO_ALTA" type="string"/
>
<property name="Usuario_modif" column="USUARIO_MODIF"
type="string"/>
<many-to-one class="Detalles_Horarios" name="Detalles"
column="idHorario" lazy="false"/>
</class>
</hibernate-mapping>
*******************************************************************************************************************
**************************************Archivo de Mapeo:
Detalles_Horarios.hb.xml *********************
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
assembly="Ausentismo"
namespace="Ausentismo.ClasesDelDominio">
<class name="Detalles_Horarios" table="T_DETALLES_HORARIOS">
<composite-id class="Detalles_Horarios_Id" name="Id">
<key-many-to-one class="Horarios_Empleados" column="ID_HORARIO"
name="Horario" foreign-key="FK_DH_HE" lazy="false"/>
<key-property column="CONTADOR" name="Contador"/>
</composite-id>
<property name="Lunes" column="LUNES" type="string"/>
<property name="Martes" column="MARTES" type="string"/>
<property name="Miercoles" column="MIERCOLES" type="string"/>
<property name="Jueves" column="JUEVES" type="string"/>
<property name="Viernes" column="VIERNES" type="string"/>
<property name="Sabado" column="SABADO" type="string"/>
<property name="Domingo" column="DOMINGO" type="string"/>
<property name="Hora_entrada" column="HORA_ENTRADA" type="string"/
>
<property name="Hora_salida" column="HORA_SALIDA" type="string"/>
<property name="Minutos_tolerancia" column="MINUTOS_TOLERANCIA"
type="string"/>
<property name="Fecha_desde" column="FECHA_DESDE" type="DateTime"/
>
<property name="Fecha_hasta" column="FECHA_HASTA" type="DateTime"/
>
<property name="Usuario_alta" column="USUARIO_ALTA" type="string"/
>
<property name="Fecha_alta" column="FECHA_ALTA" type="DateTime"/>
<property name="Usuario_modif" column="USUARIO_MODIF"
type="string"/>
<property name="Fecha_modif" column="FECHA_MODIF" type="DateTime"/
>
</class>
</hibernate-mapping>
****************************************************************************************************
Espero haber sido clara y que puedan ayudarme. Muchas gracias!!!
Erika
--
Para escribir al Grupo, hágalo a esta dirección:
[email protected]
Para más, visite: http://groups.google.com/group/NHibernate-Hispano