tags:

views:

156

answers:

2

Hello,

Im doing a project with C# winforms. This project is composed by:

alt text

  • Client project: Windows Forms where user will call the CRUD operations;
  • Server project;
  • Common Project: This project will hold the models (in the image only have the model Item);
  • ListSingleton Project: Remote Object that will do the operations on the models;

Im trying to use a 3 layers style in which the CLIENT and the SERVER will be the views layer, the LISTSINGLETON will be the controller layer (where all objects are created), and COMMON project is the models layer...

I already have all the communication working, but now I need to work on the persistence of the data in a mysql database. I was trying to use nHibernate but I’m having some troubles.

My main problem is how to organize my hibernate configuration. - In which project do I keep the mapping? Common project?

  • In which project do I keep the hibernate configuration file (App.config)? ListSingleton project?

  • In which project do I do this:

        Configuration cfg = new Configuration();
        cfg.AddXmlFile("Item.hbm.xml");
        ISessionFactory factory = cfg.BuildSessionFactory();
        ISession session = factory.OpenSession();
        ITransaction transaction = session.BeginTransaction();
    
    
    
    Item newItem = new Item("BLAA");
    
    
    // Tell NHibernate that this object should be saved
    session.Save(newItem);
    
    
    // commit all of the changes to the DB and close the ISession
    transaction.Commit();
    session.Close();
    

In the ListSingleton project? Altho I had reference to the Common Project in the ListSingleton I keep getting error in the addXml line…


  • And when I have 2 projects one with the models & mappings and another where ill use the hibernate (this project has a reference to the models project), how do i do "cfg.AddXmlFile("User.hbm.xml");" I keep geting "Could not configure datastore from file User.hbm.xml" When i use this 2 project structure.

My mapping is correct because I tried with a one-project solution and it worked :X

+2  A: 

In which project do I keep the mapping? Common project?

Yes. The mapping files should be in the same project as the models.

In which project do I keep the hibernate configuration file (App.config)? ListSingleton project?

In the client project. I'm assuming that the client project will pass objects to ListSingleton which will act on them.

In which project do I do this:

In the client project. I do want to point out that you should only create the ISessionFactory once.

Jamie Ide
+1 And I'd like to insist upon the ISessionFactory, this MUST be a singleton throughout your application as it is extremely costly to instantiate.
Will Marcouiller
Im trying to use a 3 layers style in which the client and the servers will be the **views layer**, the listSingleton will be the **controller layer** (where all objects are created), and common project is the **models layer**... So, with this new information, you think I should keep the configuration file and create the Session @ the Client? PS: I'm sorry I forgot to add this information to the question...
NoOne
I don't know, I've never done anything like that. I would do it in the layer that is responsible for handing out ISessions. ISession is serializable so you could do it in either the client or the controller.
Jamie Ide
A: 

Well I found out the answers to my questions

In which project do I keep the mapping? Common project?

As Jamie Ide said, yes it should be in the models layer.

In which project do I keep the hibernate configuration file (App.config)? ListSingleton project?

In which project do I do this:

This configuration file and all hibernate configuration should be in the controller layer, so its in the ListSingleton project;

And when I have 2 projects one with the models & mappings and another where ill use the hibernate (this project has a reference to the models project), how do i do "cfg.AddXmlFile("User.hbm.xml");" I keep geting "Could not configure datastore from file User.hbm.xml" When i use this 2 project structure.

You should configure the mapping file as Embedded Resource and Copy if newer at the propierties.

NoOne