George Silva
George Silva

Reputation: 3484

Starting with NHibernate

I'm having major difficulties to start off with NHiberante.

Main problems:

Where my hbm.xml files should reside? I create a Mappings folder but I received an error "Could not find xxx.hbm.xml file."

I tried to load the specific class through the dialect cf.AddClass(typeof(xxx)); but it still gives me the same error (the files are marked as embebed resources.

Also I'm having major problems in connection to it. I stopped trying to use the cfg xml file and tried a more direct approach with a library I have here.

Configuration cfg = new Configuration();
        cfg.AddClass(typeof(Tag));

        ISessionFactory sessions = cfg.BuildSessionFactory();
        AgnosticConnectionHandler agch = new AgnosticConnectionHandler("xxx","xxx","geo_biblio","localhost",
            5432,DatabaseInstance.PostgreSQL);
        ISession sessao = sessions.OpenSession(agch.GetConnection);

        ITransaction tx = sessao.BeginTransaction();

        Tag tag1 = new Tag();
        tag1.NomeTag = "Teste Tag NHibernate!!!";

        sessao.Save(tag1);
        tx.Commit();
        sessao.Close();

Any tips for me? I'm getting the exception in line 2 of this code, and still not sure what to do.

Any help is appreciated. Thanks

Upvotes: 0

Views: 788

Answers (1)

Rafael Mueller
Rafael Mueller

Reputation: 6083

If you're starting with nHibernate I think you really should take a look at fluent nhibernate, its way easier do develop and maintain the mapping, it even has an auto-mapping option.

Another option is confORM from Fabio Maulo (nhibernate lead developer), looks like a great tool.

Also, you can take a look at s#arp architecture, you can get some nice ideas from this project.

Upvotes: 1

Related Questions