ale
ale

Reputation: 3431

SessionFactory Configure Error

NHibernate.

I'm work with sql compaq edition, and I have many tables, I need to make the CRUDS for each one (insert, update, delete, and get).

In this moment I have a problem with the SessionFactory class.

I don't know in this point if I need write all the clasess to make the Assembly.

private static ISessionFactory _sessionFactory;

    private static ISessionFactory SessionFactory
    {
        get 
        {
            if (_sessionFactory == null)
            {
                var configuration = new Configuration();
                configuration.Configure("hibernate.cfg.xml");

//IN THE FOLLOW 3 LINES DUPLICATE MAPPING EXCEPTION.


                configuration.AddAssembly(typeof(Employee).Assembly);
                configuration.AddAssembly(typeof(SetState).Assembly);
                configuration.AddAssembly(typeof(SetPriority).Assembly);

                _sessionFactory = configuration.BuildSessionFactory();
            }
            return _sessionFactory;
        }
    }

    public static ISession OpenSession() 
    {
        return SessionFactory.OpenSession();
    }

How can I configure this, when I need work in many tables??

Upvotes: 0

Views: 203

Answers (1)

Florian Lim
Florian Lim

Reputation: 5362

When you use

configuration.AddAssembly(typeof(Employee).Assembly);

you automatically add all the classes and hbm files that are contained in the assembly, so you need only the first line and can delete the other two.

Upvotes: 3

Related Questions