views:

585

answers:

2

Hello, I would like to retrieve at runtime the values for the "dialect" and "connection.driver_class" properties specified in the configuration file.

Do you know how to do that?

Many thanks, Nicola

A: 

When you build the Configuration object and load the XML and eventually build the SessionFactory, hang on to the Configuration object reference you have.

You can use the Properties object of the Configuration reference you have, or you can do something like Dialect.GetDialect(_configuration.Properties).

chadmyers
+3  A: 

Hello chadmyers, thanks for your answer. One thing that I don't like in that solution is that I need to keep the configuration and pass it around in the methods that need the knowledge of the dialect.

I found a couple of other ways that need only a reference to the ISession of of the ISessionFactory.

From the ISession:

    public static Dialect GetDialect(ISession session)
    {
        Dialect dialect = session.GetSessionImplementation().Factory.Dialect;
        return dialect;
    }

From the ISessionFactory:

    public static Dialect GetDialect(ISessionFactory sessionFactory)
    {
        var implementor = sessionFactory as ISessionFactoryImplementor;
        Dialect dialect = implementor.Dialect;
        return dialect;
    }