-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Delphi 2005 with NHibernate
PostPosted: Mon Jun 06, 2005 11:11 am 
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!!!


Top
  
 
 Post subject:
PostPosted: Tue Jun 07, 2005 8:56 am 
Newbie

Joined: Tue Jun 07, 2005 8:45 am
Posts: 1
Hi,

We're using nHibernate with Delphi 2005 no problems. I think you may be naming things slightly incorrectly.

In your mapping file try changing:

<class name="DHB.Cliente.TCliente, DHB" table="tb_cliente">

to:

<class name="Cliente.TCliente, DHB" table="tb_cliente">


Change the name of the mapping file to be:

Cliente.TCliente.hbm.xml

Also, I don't believe you need to have the line

cfg.AddAssembly('DHB') unless you actually have the mapping file compiled into that assembly.

You just need to have the line:

cfg.AddXmlFile('Cliente.TCliente.hbm.xml');


An alternative way is to add the xml mapping file into the assembly. To do this add the hbm file to the Delphi project, then add the line:

{$R '..\Cliente.TCliente.hbm.xml'}

to the project source file. You can then just use the line cfg.AddAssembly('DHB') rather than cfg.AddXmlFile...

nHibernate searches the assembly for all files called xxxx.hbm.xml so you can add as many mapping files to the assembly as you need and don't have to call cfg,AddXMLFile for each mapping file.

Hope this helps,

Chris


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 07, 2005 4:45 pm 
Hey Chris,

Thank you... I thinks it's ok now!

Quote:
Also, I don't believe you need to have the line

cfg.AddAssembly('DHB') unless you actually have the mapping file compiled into that assembly.


How can I do that? With a {$R..} directive?

Does the App.config file is accepted under Delphi?? Can I put the map there?

[]'s

Marlos


Top
  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.