Saludos companeros.
Este es mi primer post.
Estoy empesando con NHibernate y estoy haciendo un ejercicio simple
para iniciar.
El ejemplo consiste en poder insertar en la BD un objeto llamado
Persona el cual tiene un id tipo int y un nombre tipo String, estoy
Utilizando MySQL como BD. les pongo las clases y los xml de
configuracion para ver si me pueden ayudar con mi problema. Ah ya
revise los mensajes de otros companeros q tenian el mismo problema y
aun asi no puede corregir el mio.
====================Persona.cs============================
using System;
using System.Collections.Generic;
using System.Text;
namespace Persistence
{
class Persona
{
private int id;
private String nombre;
public int Id {
set { id = value; }
get { return id; }
}
public String Nombre
{
set { nombre = value; }
get { return nombre; }
}
}
}
==================Persona.hbm.xml==================
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
namespace="Persistence" assembly="Persistence">
<class name="Persona" table="Persona" lazy="false">
<id name="Id" column="id" type="int">
<generator class="identity" />
</id>
<property name="Nombre" type="String" column="nombre"/>
</class>
</hibernate-mapping>
=================nhibernate.cfg.xml=====================
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
<session-factory name="nhibernate">
<property
name="connection.provider">NHibernate.Connection.DriverConnectionProvider</
property>
<property
name="connection.driver_class">NHibernate.Driver.MySqlDataDriver</
property>
<property name="dialect">NHibernate.Dialect.MySQLDialect</
property>
<property
name="connection.connection_string">Server=localhost;Database=nhibernate;User
ID=root;Password=destel</property>
<mapping assembly="Persistence"/>
</session-factory>
</hibernate-configuration>
==================Program.cs=========================
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using NHibernate;
using NHibernate.Cfg;
namespace Persistence
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Persona p = new Persona();
p.Id = 1;
p.Nombre = "Victor";
Configuration cfg = new Configuration();
cfg.Configure("nhibernate.cfg.xml");
ISessionFactory sesiones = cfg.BuildSessionFactory();
ISession sesion = sesiones.OpenSession();
sesion.Save(p); //AQUI ES DONDE ME TIRA LA EXCEPTION
sesion.Flush();
sesion.Close();
}
}
}
Muchas Gracias por su ayuda.
--~--~---------~--~----~------------~-------~--~----~
Para escribir al Grupo, hágalo a esta dirección:
[email protected]
Para más, visite: http://groups.google.com/group/NHibernate-Hispano
-~----------~----~----~----~------~----~------~--~---