views:

103

answers:

1

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

+1  A: 

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.

Rafael Mueller
I put an effort at NHibernate and I got it working for a very simple mapping. Thank you both for your help and i WILL definitively look at FNH
George