Hi all,
I'm trying to implement NHibernate with Delphi 2005 for .NET.
I think I'm doing everything ok, but always get the same error:
"Project DHB.exe encountered unhandled exception class NHibernate.MappingException with message 'persistent class DHB.Cliente.TCliente, DHB not found".
I have tried to do this integration with a Windows Forms Application with Delphi and VCL.NET application and got the same error with both.
Here is the code from my mapping file to a class named TCliente. My application is called DHB.exe:
Code:
<?xml version="1.0" encoding="UTF-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="DHB.Cliente.TCliente, DHB" table="tb_cliente">
<id name="ID" column="pk_id_cliente" type="Int32">
<generator class="assigned" />
</id>
<property name="Nome" column= "nome" type="String" length="50"/>
<property name="CPF" type="String" length="11"/>
<property name="DataDeNascimento" type="DateTime"/>
<property name="DataDeCadastro" type="DateTime"/>
</class>
</hibernate-mapping>
Below is the code of the unit where the TCliente class is declared:
Code:
unit Cliente;
interface
type
TCliente = class
private
FCPF: string;
FDataDeCadastro: TDateTime;
FDataDeNascimento: TDateTime;
FID: integer;
FNome: string;
public
procedure set_CPF(const Value: string);
procedure set_DataDeCadastro(const Value: TDateTime);
procedure set_DataDeNascimento(const Value: TDateTime);
procedure set_ID(const Value: integer);
procedure set_Nome(const Value: string);
public
property ID: integer read FID write set_ID;
property Nome: string read FNome write set_Nome;
property DataDeNascimento: TDateTime read FDataDeNascimento write set_DataDeNascimento;
property CPF: string read FCPF write set_CPF;
property DataDeCadastro: TDateTime read FDataDeCadastro write set_DataDeCadastro;
end;
implementation
(...)
Next is the code of the application where I'm calling the NHibernate engine to map my class to the DB.
Code:
procedure TWinForm.Button1_Click(sender: System.Object; e: System.EventArgs);
var
cfg: Configuration;
ssFactory: ISessionFactory;
ss: ISession;
cli: Cliente.TCliente;
begin
cfg := Configuration.Create;
cfg.AddAssembly('DHB');
cfg.AddXmlFile('Cliente.hbm.xml'); // <<<<< Error Here
ssFactory := cfg.BuildSessionFactory;
ss := ssFactory.OpenSession;
cli := TCliente.Create;
cli.ID := 1;
cli.Nome := 'Teste';
cli.DataDeNascimento := DateTime.Now;
cli.CPF := '97979797979';
ss.Save(cli);
ss.Close;
end;
The error occurs in cfg.AddAssembly('DHB');
I have tried to configure the mapping file too many times, but with no success.
Can someone help me?? Please!!
Thanks in advance!!!