1

I need to apply batch sizing to my NHibernate Sessions. I am using MySQL.

After finding out, that NHibernate doesn't natively support batch sizing for MySQL I installed this package:

http://www.nuget.org/packages/NHibernate.MySQLBatcher

which contains a batcher for MySQL.

Then I was searching for the point where I can inject the batcher and found this:

Why doesn't NHibernate support batching on MySql

According to the accepted answer I don't find something like this DataBaseIntegration() method.

Has anyone got through this before?

1

3 Answers 3

3

I have used this package and it worked for me.

Below the configuration I used:

var cfg = new NHibernate.Cfg.Configuration();
cfg.SetProperty(NHibernate.Cfg.Environment.ConnectionProvider, "NHibernate.Connection.DriverConnectionProvider");
cfg.SetProperty(NHibernate.Cfg.Environment.ConnectionDriver, "NHibernate.Driver.MySqlDataDriver");
cfg.SetProperty(NHibernate.Cfg.Environment.Dialect, "NHibernate.Dialect.MySQLDialect");
cfg.SetProperty(NHibernate.Cfg.Environment.UseSecondLevelCache, "false");
cfg.SetProperty(NHibernate.Cfg.Environment.UseQueryCache, "false");
cfg.SetProperty(NHibernate.Cfg.Environment.GenerateStatistics, "false");
cfg.SetProperty(NHibernate.Cfg.Environment.CommandTimeout, "300");
cfg.SetProperty(NHibernate.Cfg.Environment.BatchSize, "1000");
cfg.SetProperty(NHibernate.Cfg.Environment.BatchStrategy,  typeof(MySqlClientBatchingBatcherFactory).AssemblyQualifiedName);
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you, will check this on monday ;)
2

If using mapping by code syntax then my set up for batching in MySql looks like this (NH 3.3+):-

var configure = new Configuration().Configure();
configure.DataBaseIntegration(x =>
    {
        x.Dialect<MySQL5Dialect>();
        x.ConnectionStringName = "db";
        x.BatchSize = 50;
        x.Batcher<MySqlClientBatchingBatcherFactory>();

    })
    .Cache(x => x.UseQueryCache = true)
    .CurrentSessionContext<WebSessionContext>();

Comments

1

If using FluentNhibernate, my mapping code might help you:

Dim fConfig As FluentConfiguration
...
fConfig.ExposeConfiguration(Function(x) x.DataBaseIntegration(Sub(y)
         y.Batcher(Of MySQLBatcher.MySqlClientBatchingBatcherFactory)()
         y.BatchSize = 100
     End Sub)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.