我开始使用Nhibernate并设法让一些示例正常工作,但现在,当Nhibernate加载配置时,应用程序就会抛出这个例子。
NHibernate.MappingException: An association from the table TBL_MARCADAS refers to an unmapped class: Int32
at NHibernate.Cfg.Configuration.SecondPassCompileForeignKeys(Table table, ISet done)
at NHibernate.Cfg.Configuration.SecondPassCompile()
at NHibernate.Cfg.Configuration.BuildSessionFactory()
at BusinessLayer.entidad.inicializar() in D:\vault\BusinessLayer\entidad.vb:line 40
at BusinessLayer.TblEmpleado.getEmpleado(String ci) in D:\vault\BusinessLayer\TblEmpleado.vb:line 60
at BICWEBWS.Service1.get_minutosatraso(String str_CI) in D:\vault\BICWEBWS\App_Code\BICws.asmx.vb:line 7244
这是权利
Imports System.Collections.Generic
Imports System.Text
Imports NHibernate.Collection
Imports NHibernate.Mapping
Imports Iesi.Collections
<NHibernate.Mapping.Attributes.Class(Table:="TBL_MARCADAS")> _
Public Class TblMarcadas
Inherits entidad
Private m_codgestion As Integer
Private m_codperiodo As Integer
Private m_coddiamarcada As Integer
Private m_codempleado As Integer
Private m_codhorario As Integer
Private m_minAtrasos As Integer
Private m_cantMarcadas As Integer
Private m_horaUno As [String]
Private m_horaDos As [String]
Private m_horaTres As [String]
Private m_horaCuatro As [String]
Private m_horaCinco As [String]
Private m_horaSeis As [String]
Private m_diaLiteral As [String]
Public Sub New()
'MyBase.entidad()'
End Sub
<NHibernate.Mapping.Attributes.CompositeId(0, class:="BusinessLayer.TblMarcadas, BusinessLayer")> _
<NHibernate.Mapping.Attributes.KeyManyToOne(1, Name:="Codgestion", Column:="CODGESTION")> _
<NHibernate.Mapping.Attributes.KeyManyToOne(2, Name:="Codperiodo", Column:="CODPERIODO")> _
<NHibernate.Mapping.Attributes.KeyManyToOne(3, Name:="Coddiamarcada", Column:="CODDIAMARCADA")> _
<NHibernate.Mapping.Attributes.KeyManyToOne(4, Name:="Codempleado", Column:="CODEMPLEADO")> _
Public Overridable Property Codgestion() As Integer
Get
Return m_codgestion
End Get
Set(ByVal value As Integer)
m_codgestion = value
End Set
End Property
<NHibernate.Mapping.Attributes.Property()> _
Public Overridable Property Codperiodo() As Integer
Get
Return m_codperiodo
End Get
Set(ByVal value As Integer)
m_codperiodo = value
End Set
End Property
<NHibernate.Mapping.Attributes.Property()> _
Public Overridable Property Coddiamarcada() As Integer
Get
Return m_coddiamarcada
End Get
Set(ByVal value As Integer)
m_coddiamarcada = value
End Set
End Property
<NHibernate.Mapping.Attributes.Property()> _
Public Overridable Property Codempleado() As Integer
Get
Return m_codempleado
End Get
Set(ByVal value As Integer)
m_codempleado = value
End Set
End Property
<NHibernate.Mapping.Attributes.Property()> _
Public Overridable Property Codhorario() As Integer
Get
Return m_codhorario
End Get
Set(ByVal value As Integer)
m_codhorario = value
End Set
End Property
<NHibernate.Mapping.Attributes.Property(Column:="MIN_ATRASOS")> _
Public Overridable Property MinAtrasos() As Integer
Get
Return m_minAtrasos
End Get
Set(ByVal value As Integer)
m_minAtrasos = value
End Set
End Property
<NHibernate.Mapping.Attributes.Property(Column:="CANT_MARCADAS")> _
Public Overridable Property CantMarcadas() As Integer
Get
Return m_cantMarcadas
End Get
Set(ByVal value As Integer)
m_cantMarcadas = value
End Set
End Property
<NHibernate.Mapping.Attributes.Property(Column:="HORA_UNO")> _
Public Overridable Property HoraUno() As [String]
Get
Return m_horaUno
End Get
Set(ByVal value As [String])
m_horaUno = value
End Set
End Property
<NHibernate.Mapping.Attributes.Property(Column:="HORA_DOS")> _
Public Overridable Property HoraDos() As [String]
Get
Return m_horaDos
End Get
Set(ByVal value As [String])
m_horaDos = value
End Set
End Property
<NHibernate.Mapping.Attributes.Property(Column:="HORA_TRES")> _
Public Overridable Property HoraTres() As [String]
Get
Return m_horaTres
End Get
Set(ByVal value As [String])
m_horaTres = value
End Set
End Property
<NHibernate.Mapping.Attributes.Property(Column:="HORA_CUATRO")> _
Public Overridable Property HoraCuatro() As [String]
Get
Return m_horaCuatro
End Get
Set(ByVal value As [String])
m_horaCuatro = value
End Set
End Property
<NHibernate.Mapping.Attributes.Property(Column:="HORA_CINCO")> _
Public Overridable Property HoraCinco() As [String]
Get
Return m_horaCinco
End Get
Set(ByVal value As [String])
m_horaCinco = value
End Set
End Property
<NHibernate.Mapping.Attributes.Property(Column:="HORA_SEIS")> _
Public Overridable Property HoraSeis() As [String]
Get
Return m_horaSeis
End Get
Set(ByVal value As [String])
m_horaSeis = value
End Set
End Property
<NHibernate.Mapping.Attributes.Property(Column:="DIA_LITERAL")> _
Public Overridable Property DiaLiteral() As [String]
Get
Return m_diaLiteral
End Get
Set(ByVal value As [String])
m_diaLiteral = value
End Set
End Property
Public Overrides Function Equals(ByVal obj As [Object]) As Boolean
Return MyBase.Equals(obj)
End Function
Public Overrides Function GetHashCode() As Integer
Return MyBase.GetHashCode()
End Function
Public Overrides Function ToString() As String
Dim s As [String] = ""
s += "codgestion : " & m_codgestion.ToString() & vbLf
s += "codperiodo : " & m_codperiodo.ToString() & vbLf
s += "coddiamarcada : " & m_coddiamarcada.ToString() & vbLf
s += "codempleado : " & m_codempleado.ToString() & vbLf
s += "codhorario : " & m_codhorario.ToString() & vbLf
s += "minAtrasos : " & m_minAtrasos.ToString() & vbLf
s += "cantMarcadas : " & m_cantMarcadas.ToString() & vbLf
If m_horaUno IsNot Nothing Then
s += "horaUno : " & m_horaUno.ToString() & vbLf
Else
s += "horaUno : null" & vbLf
End If
If m_horaDos IsNot Nothing Then
s += "horaDos : " & m_horaDos.ToString() & vbLf
Else
s += "horaDos : null" & vbLf
End If
If m_horaTres IsNot Nothing Then
s += "horaTres : " & m_horaTres.ToString() & vbLf
Else
s += "horaTres : null" & vbLf
End If
If m_horaCuatro IsNot Nothing Then
s += "horaCuatro : " & m_horaCuatro.ToString() & vbLf
Else
s += "horaCuatro : null" & vbLf
End If
If m_horaCinco IsNot Nothing Then
s += "horaCinco : " & m_horaCinco.ToString() & vbLf
Else
s += "horaCinco : null" & vbLf
End If
If m_horaSeis IsNot Nothing Then
s += "horaSeis : " & m_horaSeis.ToString() & vbLf
Else
s += "horaSeis : null" & vbLf
End If
If m_diaLiteral IsNot Nothing Then
s += "diaLiteral : " & m_diaLiteral.ToString() & vbLf
Else
s += "diaLiteral : null" & vbLf
End If
Return s
End Function
Public Overridable Function GetTotalAtrasos(ByVal mes As Integer, ByVal periodo As Integer, ByVal CI As String) As Integer
' That's how the Session decide to save or to update; set NHMA.Id(UnsavedValue=x) to replace 0
Dim session As NHibernate.ISession
Try
session = _sessionFactory.OpenSession()
Dim sd As System.Collections.IList = session.Find("from TBL_MARCADAS")
Dim total As Integer
For Each marcada As TblMarcadas In sd
total += marcada.MinAtrasos
Next
Return total
Catch ex As Exception
Finally
If (session IsNot Nothing) Then
session.Close()
End If
End Try
End Function
End Class
这是表脚本
CREATE TABLE [dbo].[TBL_MARCADAS](
[CODGESTION] [int] NOT NULL,
[CODPERIODO] [int] NOT NULL,
[CODDIAMARCADA] [int] NOT NULL,
[CODEMPLEADO] [int] NOT NULL,
[CODHORARIO] [int] NULL,
[MIN_ATRASOS] [int] NULL,
[CANT_MARCADAS] [int] NULL,
[HORA_UNO] [char](10) NULL,
[HORA_DOS] [char](10) NULL,
[HORA_TRES] [char](10) NULL,
[HORA_CUATRO] [char](10) NULL,
[HORA_CINCO] [char](10) NULL,
[HORA_SEIS] [char](10) NULL,
[DIA_LITERAL] [char](10) NULL,
PRIMARY KEY CLUSTERED
(
[CODGESTION] ASC,
[CODPERIODO] ASC,
[CODDIAMARCADA] ASC,
[CODEMPLEADO] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
这是NHibernate.mappings序列化程序抛出的内容:
<?xml version="1.0" encoding="utf-8"?>
<!--Generated from NHibernate.Mapping.Attributes on 2010-06-24 08:27:58Z.-->
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="BusinessLayer.TblEmpleado, BusinessLayer" table="TBL_EMPLEADO">
<id name="codempleado">
<generator class="native" />
</id>
<property name="Nombre" />
<property name="ApellidoP" column="APELLIDO_P" />
<property name="ApellidoM" column="APELLIDO_M" />
<property name="FechaIngreso" column="FECHA_INGRESO" />
<property name="Cargo" />
<property name="SueldoActual" column="SUELDO_ACTUAL" />
<property name="Foto" />
<property name="Estadoempleado" />
<property name="Codregional" />
<property name="Codseguro" />
<property name="Codhorario" />
<property name="FechaNac" column="FECHA_NAC" />
<property name="Sexo" />
<property name="Ci" />
<property name="Expedido" />
<property name="Nacionalidad" />
<property name="TipoTrabajador" column="TIPO_TRABAJADOR" />
</class>
<class name="BusinessLayer.TblMarcadas, BusinessLayer" table="TBL_MARCADAS">
<composite-id class="TblMarcadas">
<key-many-to-one name="Codgestion" column="CODGESTION" />
<key-many-to-one name="Codperiodo" column="CODPERIODO" />
<key-many-to-one name="Coddiamarcada" column="CODDIAMARCADA" />
<key-many-to-one name="Codempleado" column="CODEMPLEADO" />
</composite-id>
<property name="Codperiodo" />
<property name="Coddiamarcada" />
<property name="Codempleado" />
<property name="Codhorario" />
<property name="MinAtrasos" column="MIN_ATRASOS" />
<property name="CantMarcadas" column="CANT_MARCADAS" />
<property name="HoraUno" column="HORA_UNO" />
<property name="HoraDos" column="HORA_DOS" />
<property name="HoraTres" column="HORA_TRES" />
<property name="HoraCuatro" column="HORA_CUATRO" />
<property name="HoraCinco" column="HORA_CINCO" />
<property name="HoraSeis" column="HORA_SEIS" />
<property name="DiaLiteral" column="DIA_LITERAL" />
</class>
</hibernate-mapping>
非常感谢您的时间
答案 0 :(得分:0)
好吧,我发现了问题。
我不知道为什么自动生成工具使用了多对一键:
<composite-id class="TblMarcadas">
<key-many-to-one name="Codgestion" column="CODGESTION" />
<key-many-to-one name="Codperiodo" column="CODPERIODO" />
<key-many-to-one name="Coddiamarcada" column="CODDIAMARCADA" />
<key-many-to-one name="Codempleado" column="CODEMPLEADO" />
</composite-id>
我刚刚将其更改为key-property。
也许是因为这张桌子上有外键?
任何希望这有助于一个人再见