Hola, programando en Nhibernate obtengo el siguiente error sin poder encontrar una solución, el error que obtengo es
Excepción no controlada del tipo 'NHibernate.MappingException' en nhibernate.dll
Información adicional: Could not add assembly Persona
Os escribo aquí los diferentes archivos para ver si me podeis ayudar.
Fichero de configuración: App.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name = "nhibernate" type = "System.Configuration.NameValueSectionHandler, System, Version = 1.0.5000.0, Culture = neutral, PublicKeyToken=b77a5c561934e089" />
</configSections>
<nhibernate>
<add key = "hibernate.connection.provider" value = "Nhibernate.Connection.DriverConnectionProvide r" />
<add key = "hibernate.dialect" value = "Nhibernate.Dialect.MsSql2000Dialect" />
<add key = "hibernate.connection.driver_class" value = "Nhibernate.Driver.SqlClientDriver" />
<add key = "hibernate.connection.connection_string" value = "Server = server; DataBase = db; User Id = sa; Password = *****" />
</nhibernate>
</configuration>
Fichero mapeo de la clase: Persona.hbm.xml
<?xml version="1.0" encoding="utf-8" ?>
<hibernate - mapping xmlns = "urn: nhibernate-mapping-2.2">
<class name = "Persona" table = "HibernateProva">
<id name = "Dni">
<column name = "Dni" type = "String" not-null="true" />
<generator class = "uuid.hex" />
</id>
<property name = "nom" column = "nom" />
</class>
</hibernate>
Fichero clase persona: Persona.vb
Public Class Persona
Private _dni As String
Private _nom As String
Public Property dni() As String
Get
Return _dni
End Get
Set(ByVal Value As String)
_dni = Value
End Set
End Property
Public Property Nom() As String
Get
Return _nom
End Get
Set(ByVal Value As String)
_nom = Value
End Set
End Property
End Class
Ahora lo que hago es en un formulario insertar un boton para cuando lo clicke inserte en la base de datos, para ello escribo en el fichero form1.vb el siguiente código:
Imports System
Imports NHibernate
Imports NHibernate.Cfg
Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Código generado por el Diseñador de Windows Forms "
Public Sub New()
MyBase.New()
'El Diseñador de Windows Forms requiere esta llamada.
InitializeComponent()
'Agregar cualquier inicialización después de la llamada a InitializeComponent()
End Sub
'Form reemplaza a Dispose para limpiar la lista de componentes.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Requerido por el Diseñador de Windows Forms
Private components As System.ComponentModel.IContainer
'NOTA: el Diseñador de Windows Forms requiere el siguiente procedimiento
'Puede modificarse utilizando el Diseñador de Windows Forms.
'No lo modifique con el editor de código.
Friend WithEvents Button1 As System.Windows.Forms.Button
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.Button1 = New System.Windows.Forms.Button()
Me.SuspendLayout()
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(96, 80)
Me.Button1.Name = "Button1"
Me.Button1.TabIndex = 0
Me.Button1.Text = "Button1"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(292, 266)
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.Button1})
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim individu As New Persona()
Dim cfg As New NHibernate.Cfg.Configuration()
cfg.AddAssembly("Persona")
Dim factory As ISessionFactory = cfg.BuildSessionFactory()
Dim session As ISession = factory.OpenSession()
Dim transaction As ITransaction = session.BeginTransaction()
individu.dni = "53224311-B"
individu.Nom = "Vicent"
session.Save(individu)
transaction.Commit()
session.Close()
End Sub
End Class
Después de repasar no veo donde encontrar el error, agradecería vuestra ayuda. Un saludo a tod@s.